fix language state intialization

This commit is contained in:
Chad Pilkey 2017-11-29 18:19:43 -05:00
parent 72e3fb1478
commit e4c33baf86
2 changed files with 19 additions and 19 deletions

View File

@ -42,7 +42,7 @@ with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
} }
private function changeLanguage():void { private function changeLanguage():void {
ResourceUtil.getInstance().setPreferredLocale(selectedItem); ResourceUtil.getInstance().setPreferredLocale(selectedItem.code);
} }
]]> ]]>
</fx:Script> </fx:Script>

View File

@ -91,10 +91,9 @@ package org.bigbluebutton.util.i18n
if (preferredLocale != MASTER_LOCALE) { if (preferredLocale != MASTER_LOCALE) {
LOGGER.debug("Preferred locale=" + preferredLocale + " is not the same as master locale=" + MASTER_LOCALE); LOGGER.debug("Preferred locale=" + preferredLocale + " is not the same as master locale=" + MASTER_LOCALE);
// Improve language detection // Improve language detection
setPreferredLocale({code:preferredLocale, direction:"ltr"}); setPreferredLocale(preferredLocale);
} else { } else {
inited = true; localeChangeComplete();
dispatcher.dispatchEvent(new LocaleChangeEvent(LocaleChangeEvent.LOCALE_INIT));
} }
} }
@ -123,12 +122,12 @@ package org.bigbluebutton.util.i18n
return ExternalInterface.call("getLanguage"); return ExternalInterface.call("getLanguage");
} }
private function isPreferredLocaleAvailable(prefLocale:String):Boolean { private function findPreferredLocale(prefLocale:String):Object {
for each(var item:* in locales) { for each(var item:* in locales) {
if (prefLocale == item.code) if (prefLocale == item.code)
return true; return item;
} }
return false; return null;
} }
private function getIndexForLocale(prefLocale:String):int { private function getIndexForLocale(prefLocale:String):int {
@ -139,19 +138,19 @@ package org.bigbluebutton.util.i18n
return -1; return -1;
} }
public function setPreferredLocale(locale:Object):void { public function setPreferredLocale(localeCode:String):void {
var localeCode : String = locale.code;
if (localeCode == DEFAULT_LOCALE_IDENTIFIER) { if (localeCode == DEFAULT_LOCALE_IDENTIFIER) {
localeCode = getDefaultLocale(); localeCode = getDefaultLocale();
} }
if (isPreferredLocaleAvailable(localeCode)) { var localeInfo:Object = findPreferredLocale(localeCode)
if (localeInfo != null) {
preferredLocale = localeCode; preferredLocale = localeCode;
}else{ }else{
preferredLocale = MASTER_LOCALE; preferredLocale = MASTER_LOCALE;
} }
preferredDirection = locale.direction; preferredDirection = localeInfo.direction;
changeLocale(preferredLocale); changeLocale(preferredLocale);
} }
@ -201,19 +200,12 @@ package org.bigbluebutton.util.i18n
changeLocaleHelper(locale); changeLocaleHelper(locale);
} }
private function localeChangeComplete(event:ResourceEvent):void { private function localeChangeComplete(event:ResourceEvent=null):void {
// Set the preferred locale and master as backup. // Set the preferred locale and master as backup.
if (preferredLocale != MASTER_LOCALE) { if (preferredLocale != MASTER_LOCALE) {
ResourceManager.getInstance().localeChain = [preferredLocale, MASTER_LOCALE]; ResourceManager.getInstance().localeChain = [preferredLocale, MASTER_LOCALE];
} else { } else {
if (preferredLocale != MASTER_LOCALE) {
var logData:Object = UsersUtil.initLogData();
logData.tags = ["locale"];
logData.message = "Failed to load locale = " + preferredLocale;
LOGGER.debug(JSON.stringify(logData));
}
ResourceManager.getInstance().localeChain = [MASTER_LOCALE]; ResourceManager.getInstance().localeChain = [MASTER_LOCALE];
preferredLocale = MASTER_LOCALE;
} }
update(); update();
@ -225,6 +217,14 @@ package org.bigbluebutton.util.i18n
*/ */
private function handleResourceNotLoaded(event:ResourceEvent):void { private function handleResourceNotLoaded(event:ResourceEvent):void {
LOGGER.debug("Resource locale [" + preferredLocale + "] could not be loaded."); LOGGER.debug("Resource locale [" + preferredLocale + "] could not be loaded.");
if (preferredLocale != MASTER_LOCALE) {
var logData:Object = UsersUtil.initLogData();
logData.tags = ["locale"];
logData.message = "Failed to load locale = " + preferredLocale;
LOGGER.debug(JSON.stringify(logData));
}
ResourceManager.getInstance().localeChain = [MASTER_LOCALE]; ResourceManager.getInstance().localeChain = [MASTER_LOCALE];
preferredLocale = MASTER_LOCALE; preferredLocale = MASTER_LOCALE;
update(); update();