2011-11-12 37 views
0

好的。我一直在網絡中尋找一種無頭痛的國際化方式。我終於找到了手段。包括在你的構建PARAMS的語言環境,以及這樣做-locale locale/{locale}的事情,使他們成爲性的資源管理器文件(即:locale/en_GB/lang.properties在src文件夾。)Flex國際化問題(在onCreationComplete中選擇區域設置)

問題:我似乎無法設置用戶對啓動區域。我得到「的LocaleID指數超出範圍」一些錯誤(這是奇怪的,因爲是的LocaleID基於字符串..?)

這部分工作正常:

<fx:Script> 
    <![CDATA[ 
     // Shorthand resource management. 
     private function getLang(key:String):String 
     { return resourceManager.getString(key, 'lang'); } 
    ]]> 
</fx:Script> 

這部分不工作:

protected function creationCompleteHandler(event:FlexEvent):void 
{ 
    var locale:LocaleID = new LocaleID("en_GB"); 
    trace(locale.getLanguage()); // en 
    trace(locale.getRegion()); // GB 
    trace(locale.name); // en-GB 

    if (!empty(saveData.data.lang)) // empty checks if str == null or trim(str).length == 0 
     locale = new LocaleID(saveData.data.lang); 

    this.setStyle("locale", locale); 
} 

當我設置的語言環境未拋出的實際的錯誤,但是當在UI對象試圖讓他們的價值觀。完整的錯誤消息如下:

RangeError: Property locale value [object LocaleID] is out of range 
    at flashx.textLayout.property::Property$/defaultErrorHandler()[C:\Vellum\branches\v2\2.0\dev\output\openSource\textLayout\src\flashx\textLayout\property\Property.as:31] 
    at flashx.textLayout.property::Property/setHelper()[C:\Vellum\branches\v2\2.0\dev\output\openSource\textLayout\src\flashx\textLayout\property\Property.as:230] 
    at flashx.textLayout.formats::TextLayoutFormat/setStyleByProperty()[C:\Vellum\branches\v2\2.0\dev\output\openSource\textLayout\src\flashx\textLayout\formats\TextLayoutFormat.as:628] 
    at flashx.textLayout.formats::TextLayoutFormat/set locale()[C:\Vellum\branches\v2\2.0\dev\output\openSource\textLayout\src\flashx\textLayout\formats\TextLayoutFormat.as:1271] 
    at spark.core::CSSTextLayoutFormat()[E:\dev\4.5.1\frameworks\projects\spark\src\spark\core\CSSTextLayoutFormat.as:75] 
    at spark.components::RichEditableText/updateStylesIfChanged()[E:\dev\4.5.1\frameworks\projects\spark\src\spark\components\RichEditableText.as:3619] 
    at spark.components::RichEditableText/commitProperties()[E:\dev\4.5.1\frameworks\projects\spark\src\spark\components\RichEditableText.as:2491] 
    at mx.core::UIComponent/validateProperties()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\core\UIComponent.as:8209] 
    at mx.managers::LayoutManager/validateProperties()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:597] 
    at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:813] 
    at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1180] 

有趣的事實: 1.我的名字是不是牛皮紙 2.我的SDK是不是E:\dev\4.5.1 ......這是在C:\Program Files\Adobe\Adobe Flash Builder 4.5.1\sdks\4.5.1(?)。好工作的錯誤信息!使用原來的構建路徑和所有...

+0

存在堆棧跟蹤中顯示的構建路徑問題與構建框架SWC的方式有關。我認爲當你創建一個包含用於創建代碼提示的所有ASDoc和元數據的「FAT SWC」時,刪除這些開發路徑是不可能的。我對細節有些模糊;但這是我的理解。 – JeffryHouser

+0

我設法以非常討厭的方式解決這個問題,所以我想我會寫出答案。我每天都越來越討厭Flex,因爲我看到Adobe做得太差了。 – cbroughton

+0

作爲供參考,這些運行時錯誤是從textLayout框架生成的;而不是來自Flex框架代碼。我並不是說Flex就沒有問題;但你目前的錯誤不是其中之一。 – JeffryHouser

回答

1

實際的「修復」這個問題很噁心,但它的工作:

protected function creationCompleteHandler(event:FlexEvent):void 
{ 
    var locale:String = LocaleID.DEFAULT.name.replace("-", "_"); // en_GB 

    if (!empty(saveData.data.lang)) // empty checks if str == null or trim(str).length == 0 
     locale = saveData.data.lang; 

    resourceManager.localeChain = [locale, "en_GB"]; 
} 

爲什麼?因爲似乎Flex文檔(如此美妙的東西)再次過時了。在Flex4.5中使用this.setStyle("locale", locale)實際上是錯誤的。而是更新resourceManager的languageChain以將首選語言環境作爲第一選項。

根據醜陋的命名行中的廣告,這是從「LocaleID」中獲取「en_GB」的唯一方法。要麼是字符串連接,這也很醜陋。太糟糕了,resourceManager不會將破折號用作下劃線。

0

locale style應該有一個字符串值;但您正在使用LocaleID對象進行設置。我敢肯定,你要做到這一點:

this.setStyle("locale", "en_GB"); 

這裏是關於LocaleID object一些更多的信息。

+1

是的,不幸的是,像這樣設置也會產生相同的奇數範圍錯誤。我在嘗試這個解決方案之前發佈在這裏,當我跑過LocaleID的東西;人們告訴我使用它和LocaleID.DEFAULT ... :( – cbroughton