Localize IMA based on device locale by default
#exofixit PiperOrigin-RevId: 343871061
This commit is contained in:
parent
ffc6a0d5f7
commit
689e89e5f3
@ -88,6 +88,8 @@
|
||||
* Notify onBufferingEnded when the state of origin player becomes
|
||||
STATE_IDLE or STATE_ENDED.
|
||||
* Allow to remove all playlist items that makes the player reset.
|
||||
* IMA extension:
|
||||
* Set the overlay language based on the device locale by default.
|
||||
|
||||
### 2.12.1 (2020-10-23) ###
|
||||
|
||||
|
@ -58,6 +58,7 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -544,7 +545,9 @@ public final class ImaAdsLoader implements Player.EventListener, AdsLoader {
|
||||
private static final class DefaultImaFactory implements ImaUtil.ImaFactory {
|
||||
@Override
|
||||
public ImaSdkSettings createImaSdkSettings() {
|
||||
return ImaSdkFactory.getInstance().createImaSdkSettings();
|
||||
ImaSdkSettings settings = ImaSdkFactory.getInstance().createImaSdkSettings();
|
||||
settings.setLanguage(getImaLanguageCodeForDefaultLocale());
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -585,5 +588,16 @@ public final class ImaAdsLoader implements Player.EventListener, AdsLoader {
|
||||
return ImaSdkFactory.getInstance()
|
||||
.createAdsLoader(context, imaSdkSettings, adDisplayContainer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a language code that's suitable for passing to {@link ImaSdkSettings#setLanguage} and
|
||||
* corresponds to the device's {@link Locale#getDefault() default Locale}.
|
||||
*/
|
||||
// TODO: It may be possible to define a better mapping onto IMA's supported language codes. See:
|
||||
// https://developers.google.com/interactive-media-ads/docs/sdks/android/client-side/localization.
|
||||
// IMA will fall back to its default language code ("en") if the value returned is unsupported.
|
||||
private static String getImaLanguageCodeForDefaultLocale() {
|
||||
return Util.splitAtFirst(Util.getSystemLanguageCodes()[0], "-")[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user