reflex/reflex-framework

Runtime Error when using [ResourceBundle()] and states

Closed this issue · 0 comments

When using ResourceBundle in an application that uses states, user receives runtime error:

Error: Could not find compiled resource bundle 'core' for locale 'en_US'.
at mx.resources::ResourceManagerImpl/installCompiledResourceBundle()[E:\dev\4.x\frameworks\projects\framework\src\mx\resources\ResourceManagerImpl.as:340]
at mx.resources::ResourceManagerImpl/installCompiledResourceBundles()[E:\dev\4.x\frameworks\projects\framework\src\mx\resources\ResourceManagerImpl.as:269]
at mx.resources::ResourceManagerImpl/supportNonFrameworkApps()[E:\dev\4.x\frameworks\projects\framework\src\mx\resources\ResourceManagerImpl.as:948]
at mx.resources::ResourceManagerImpl/findBundle()[E:\dev\4.x\frameworks\projects\framework\src\mx\resources\ResourceManagerImpl.as:916]
at mx.resources::ResourceManagerImpl/getString()[E:\dev\4.x\frameworks\projects\framework\src\mx\resources\ResourceManagerImpl.as:751]

Use the following code to recreate

<?xml version="1.0" encoding="utf-8"?>
<rx:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:rx="http://rx.reflex.io/2010"
           width="300" height="300">

<fx:Metadata>
    [ResourceBundle("YourApplication")]
</fx:Metadata>

<fx:Script>
    <![CDATA[
        import mx.resources.IResourceManager;
        import mx.resources.ResourceManager;
        [Bindable]
        public var resource:IResourceManager = ResourceManager.getInstance();
    ]]>
</fx:Script>

<rx:states>
</rx:states>

<rx:Label text="{resource.getString('YourApplication', 'title')}" />

</rx:Application>

Where 'YourApplication' is the name of your properties file in locales/{locale} ({locale} == your default locale. Mine is 'en_US')

The only work around I have found is to trick the compiler into thinking the property files exist.

Create the following files in your locales/{locale} folder:

  • core.properties
  • effects.properties
  • styles.properties
  • skins.properties

Then include the following items in your Application file:

<rx:Application ...
    <fx:Metadata>
    [ResourceBundle("core")]
    [ResourceBundle("styles")]
    [ResourceBundle("skins")]
    [ResourceBundle("effects")]
    </fx:Metadata>

Then use your [ResourceBundle("YourApplication")] tag as expected.
...