mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-25 19:25:43 +00:00
Bug 1245722 - Replace org.mozilla.gecko.sync.Utils.getLanguageTag with Locales.getLanguageTag. r=nalexander
The code at was duplicated for build reasons that no longer apply. MozReview-Commit-ID: Hk7n9beobsY --HG-- extra : rebase_source : 8ca84ecb2c837d14182b706014ab98022ce95acc
This commit is contained in:
parent
6cb9ebeb48
commit
5a0e601907
@ -9,6 +9,7 @@ import org.mozilla.gecko.background.fxa.FxAccountClientException
|
||||
.FxAccountClientMalformedResponseException;
|
||||
import org.mozilla.gecko.background.fxa.FxAccountClientException.FxAccountClientRemoteException;
|
||||
import org.mozilla.gecko.fxa.FxAccountConstants;
|
||||
import org.mozilla.gecko.Locales;
|
||||
import org.mozilla.gecko.sync.ExtendedJSONObject;
|
||||
import org.mozilla.gecko.sync.Utils;
|
||||
import org.mozilla.gecko.sync.crypto.HKDF;
|
||||
@ -280,7 +281,7 @@ public class FxAccountClient20 implements FxAccountClient {
|
||||
|
||||
// The basics.
|
||||
final Locale locale = Locale.getDefault();
|
||||
request.addHeader(HttpHeaders.ACCEPT_LANGUAGE, Utils.getLanguageTag(locale));
|
||||
request.addHeader(HttpHeaders.ACCEPT_LANGUAGE, Locales.getLanguageTag(locale));
|
||||
request.addHeader(HttpHeaders.ACCEPT, ACCEPT_HEADER);
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ import org.mozilla.gecko.background.fxa.FxAccountClientException;
|
||||
import org.mozilla.gecko.background.fxa.oauth.FxAccountAbstractClientException.FxAccountAbstractClientMalformedResponseException;
|
||||
import org.mozilla.gecko.background.fxa.oauth.FxAccountAbstractClientException.FxAccountAbstractClientRemoteException;
|
||||
import org.mozilla.gecko.fxa.FxAccountConstants;
|
||||
import org.mozilla.gecko.Locales;
|
||||
import org.mozilla.gecko.sync.ExtendedJSONObject;
|
||||
import org.mozilla.gecko.sync.Utils;
|
||||
import org.mozilla.gecko.sync.net.AuthHeaderProvider;
|
||||
import org.mozilla.gecko.sync.net.BaseResource;
|
||||
import org.mozilla.gecko.sync.net.BaseResourceDelegate;
|
||||
@ -217,7 +217,7 @@ public abstract class FxAccountAbstractClient {
|
||||
|
||||
// The basics.
|
||||
final Locale locale = Locale.getDefault();
|
||||
request.addHeader(HttpHeaders.ACCEPT_LANGUAGE, Utils.getLanguageTag(locale));
|
||||
request.addHeader(HttpHeaders.ACCEPT_LANGUAGE, Locales.getLanguageTag(locale));
|
||||
request.addHeader(HttpHeaders.ACCEPT, ACCEPT_HEADER);
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
|
||||
import org.mozilla.gecko.fxa.login.State;
|
||||
import org.mozilla.gecko.fxa.sync.FxAccountSyncAdapter;
|
||||
import org.mozilla.gecko.fxa.sync.FxAccountSyncStatusHelper;
|
||||
import org.mozilla.gecko.Locales;
|
||||
import org.mozilla.gecko.sync.ThreadPool;
|
||||
import org.mozilla.gecko.sync.Utils;
|
||||
|
||||
@ -229,7 +230,7 @@ public class FirefoxAccounts {
|
||||
public static String getOldSyncUpgradeURL(final Resources res, final Locale locale) {
|
||||
final String VERSION = AppConstants.MOZ_APP_VERSION;
|
||||
final String OS = AppConstants.OS_TARGET;
|
||||
final String LOCALE = Utils.getLanguageTag(locale);
|
||||
final String LOCALE = Locales.getLanguageTag(locale);
|
||||
return res.getString(R.string.fxaccount_link_old_firefox, VERSION, OS, LOCALE);
|
||||
}
|
||||
}
|
||||
|
@ -562,36 +562,4 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gecko uses locale codes like "es-ES", whereas a Java {@link Locale}
|
||||
* stringifies as "es_ES".
|
||||
*
|
||||
* This method approximates the Java 7 method <code>Locale#toLanguageTag()</code>.
|
||||
* <p>
|
||||
* <b>Warning:</b> all consumers of this method will need to be audited when
|
||||
* we have active locale switching.
|
||||
*
|
||||
* @return a locale string suitable for passing to Gecko.
|
||||
*/
|
||||
public static String getLanguageTag(final Locale locale) {
|
||||
// If this were Java 7:
|
||||
// return locale.toLanguageTag();
|
||||
|
||||
String language = locale.getLanguage(); // Can, but should never be, an empty string.
|
||||
// Modernize certain language codes.
|
||||
if (language.equals("iw")) {
|
||||
language = "he";
|
||||
} else if (language.equals("in")) {
|
||||
language = "id";
|
||||
} else if (language.equals("ji")) {
|
||||
language = "yi";
|
||||
}
|
||||
|
||||
String country = locale.getCountry(); // Can be an empty string.
|
||||
if (country.equals("")) {
|
||||
return language;
|
||||
}
|
||||
return language + "-" + country;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user