You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by Dirk Eismann <bo...@googlemail.com> on 2012/06/12 15:27:09 UTC

Asset / i18n resource management improvements

I'm currently experimenting on how to improve resource management in
future Apache Flex versions.

It all started when I wanted to mimic the Android IDE (ADT) behavior
where ADT automatically creates a class R with static accessors for
project resources. E.g. a default Android project has a /src and a
/res folder. If you put a foo.jpg into the /res/drawable folder, the
ADT creates R.drawable.foo that can be referred to in your code (where
foo is actually a int that's used for resource loading at runtime,
more info here [1])

So I jumped in and created a plugin for Eclipse / Flash Builder that
does the same by autogenerating a R.as class with static fields that
are used to [Embed] image assets. As soon as you drop images into
/res/images inside of a FB project, the R.as class gets updated etc.
This happens before the mxmlc compiler starts a compilation run, so
you can do this in your code

<s:Image source="{R.images.foo}"/>

This works pretty nicely, although as of now it's only working in FB /
Eclipse, not with CLI builds (yet) [2]

The next thing on my list was to improve ResourceBundle / i18n
handling a bit. I'm too tired to use ResourceManager.getInstance or
resourceManager.getString("foo", "bar") all the way which is annoying
to type and error prone. Would be much nicer to have code hinting here
as well. Ideally, I'd like to do

  <s:Label text="{R.bundles.myBundle.foo}"/>

which would get the value of the key "foo" from ResourceBundle
"myBundle". Another way would be to have a class B (for Bundles) which
is even less typing

  <s:Label text="{B.myBundle.foo}"/>

or something like this.The general idea is to avoid too much typing
and taking advantage of what an IDE offers you in terms of code
hinting.

The nice side effect of this "less code to type" approach is that you
get "less errors that will happen" as well since all asset / resource
accesses are checked by the compiler.

Currently I have a few ideas and things I would like to implement:

1) envision how a default project layout for a Flex project could look
like. As of now a default project has a /src folder. Maybe we can
agree that it's a good idea to put place assets into an /assets or
/resources folder. This would be the default path that is used for
automatic asset / bundle transformation and code generation

2) create a compiler extension for mxmlc or a patched version of the
flex2.compiler.i18n.I18nCompiler that automatically generates / emits
code for the R class and modifying the code that gets generated for
the mx.resource.ResourceBundle sublasses without breaking backwards
compatibility (so you can still do @Resource or
resourceManager.getString())

3) create a Ecipse / FB plugin that uses the "rules" from 1) and the
compiler extension from 2) to streamline this in the IDE (as of now I
am an FB / Eclipse user so I can only provide Elcipse plugin know-how,
I have not yet done anything with IntelliJ or any other Flex IDE)

So... what do you think? I would also like to know what other people
have in mind concerning asset / resource bundle management, maybe we
can team up?

Cheers,
Dirk.

[1] http://developer.android.com/guide/topics/resources/index.html
[2] https://plus.google.com/u/0/111304077092175055051/posts/St8TkR4DFLY

Re: Asset / i18n resource management improvements

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> Both implementations are inefficient given how often you tend to look up
> strings.  You are initializing all of these properties when it isn't even
> clear they will be used.  I still think you are better off just embedding a
> delimited text file and parsing it on the fly.  But it still needs proving.
The reason why this is not usually done is (in the case or error messages) at the point of the error you need to know for sure what you want to display is available and you may have to display it under limited time or memory constraints. Having everything preloaded even if you don't use it means you don;t get an "Out of memory" error when trying to display an "Out of memory" error message :-) . I'm not sure we need to worry about this in the Flex SDK however and could load when required.

Performance may or may not be an issue when using resources for languages, but I assume we're talking about only change how the SDK does it internally for it own error messages?

Thinking a little more about the patch file idea and I think a better idea would be to automatically add a language only locale eg "en", "fr", "sp" etc to the end of the locale chain. Less stuffing about with build files and would help anyone working with multiple variants of the same language and it commonly used.

Thanks
Justin


Re: Asset / i18n resource management improvements

Posted by Alex Harui <ah...@adobe.com>.


On 6/12/12 3:39 PM, "Om" <bi...@gmail.com> wrote:


> Yes, we do bake classes for these bundles but still, the implementation is
> such that it is useless for autocompletion and compile time checks.  From
> the docs[1], here is the generated class for a resource bundle in the
> current implementation:
> 
> public class RegistrationForm_properties extends ResourceBundle {
>     override protected function getContent():Object {
>         var properties:Object = {};
>         properties["registration_button"] = "Registration";
>         properties["submit_button"] = "Submit Form";
>         properties["personname"] = "Name";
>         .
>         .
>         .
>         return properties;
>     }
> }
> 
> The new way would be something like (Dirk, please correct me if I am off here)
> :
> 
> public class RegistrationForm_properties {
>         public static var registration_button:String = "Registration";
>         public static var submit_button:String = "Submit Form";
>         public static var personname:String = "Name";
>         .
>         .
>         .
>     }
> }
> 
> Runtime overhead wise, the second implementation will be a bit lesser
> because we
> dont use the generic object or any do any dynamic key lookup.
Both implementations are inefficient given how often you tend to look up
strings.  You are initializing all of these properties when it isn't even
clear they will be used.  I still think you are better off just embedding a
delimited text file and parsing it on the fly.  But it still needs proving.

> I dont think we should use dynamic classes at all.  Which is kind of
> what happens today.  It causes poor runtime
> 
> performance and it does not help in compile time.
The use of dynamic property access is not causing poor runtime performance,
it is this particular implementation (wrapping an object in a class).  For
casual occasional access, dynamic access is more efficient than a lot of
class and object initialization code that never gets a chance to pay off.
> 
> But it wont generate compiler errors/warnings for missing keys or
> wrong key usage.
It doesn't today, and won't tomorrow.  But my point is that some future IDE
could by learning how to read the properties files in the project.

-- 
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui


Re: Asset / i18n resource management improvements

Posted by Om <bi...@gmail.com>.
>
> To me, the most important thing to get right is the run-time
> implementation.
> Once we nail that, someone will figure out how to get you something like
> code-hinting.
>

Just to be clear, the benefit is not only code-hinting, it is also compile
time error checking.  If a key does not appear in autocomplete and the user
goes ahead and tries to use it, there will a warning/error generated
depending on how we want to implement it.  It will also be useful during
refactoring of code.

Fundamentally, IMO, a string-only resource system is a simple lookup table
> of a string key to a longer string.  Then for organizational purposes folks
> tend to group those keys into bundles.
>
> What we do today is bake classes for these bundles.  Then we install these
> classes into a manager at startup time.  And we do that for error strings
> you may never see, and Alert labels you hopefully will not see before the
> first screen appears.  And the classes are actually quite big compared to
> simply embedding a string table in the SWF (or loading the string table at
> runtime).   Also, it isn't clear you need a class.  You might be able to
> use
> simple dynamic objects instead.
>
>
Yes, we do bake classes for these bundles but still, the implementation is
such that it is useless for autocompletion and compile time checks.  From
the docs[1], here is the generated class for a resource bundle in the
current implementation:

public class RegistrationForm_properties extends ResourceBundle {
    override protected function getContent():Object {
        var properties:Object = {};
        properties["registration_button"] = "Registration";
        properties["submit_button"] = "Submit Form";
        properties["personname"] = "Name";
        .
        .
        .
        return properties;
    }
}

The new way would be something like (Dirk, please correct me if I am off here) :

public class RegistrationForm_properties {
        public static var registration_button:String = "Registration";
        public static var submit_button:String = "Submit Form";
        public static var personname:String = "Name";
        .
        .
        .
    }
}

Runtime overhead wise, the second implementation will be a bit lesser
because we
dont use the generic object or any do any dynamic key lookup.


And the classes are actually quite big compared to
>  simply embedding a string table in the SWF (or loading the string table at
> runtime).   Also, it isn't clear you need a class.  You might be able to
> use
> simple dynamic objects instead.
>
> And if we decide that classes have too much overhead and simply use dynamic
> objects, what would then happen to code hinting?  There wouldn't be any
> classes to hint.  How would you find spelling errors in the keys?  I'd hate
> to see us drag down runtime performance just so you can get code-hinting.


I dont think we should use dynamic classes at all.  Which is kind of
what happens today.  It causes poor runtime

performance and it does not help in compile time.

I think some IDE will someday be smart enough to look at the string tables
> and help you get your keys right.
>

But it wont generate compiler errors/warnings for missing keys or
wrong key usage.

[1] http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7f2d.html#WS2db454920e96a9e51e63e3d11c0bf69084-7f34

Re: Asset / i18n resource management improvements

Posted by Greg Lafrance <gl...@ipass.com>.
Its possible you might "localize" an image, sound file, video file, css,
etc. Strings only is so 1990's :-)

On Tue, Jun 12, 2012 at 1:13 PM, Gordon Smith <go...@adobe.com> wrote:

> > only Strings. I always found it strange to have Embeds and
> ClassReferences in .properties files.
>
> Nobody ever needs to localize an embedded image?
>
> - Gordon
>
>
> -----Original Message-----
> From: Dirk Eismann [mailto:bortsen@googlemail.com]
> Sent: Tuesday, June 12, 2012 12:47 PM
> To: flex-dev@incubator.apache.org
> Subject: Re: Asset / i18n resource management improvements
>
> Hi Alex,
>
> > IMO, something like an "R" class should not be put into the compiler
> > or the IDE.  The compiler should be as framework agnostic as possible.
> > It is probably possible to create a set of classes that do what R does.
>
> maybe I misuderstand you here, but to get compile time code hinting in an
> IDE and compile time checking for resource accesses, I wonder how something
> like R should be generated then if not by the compiler?
>
> > How many of you use non-String resources?  A String-only resource
> > system can be so much better optimized than what we have now.  I would
> > love to phase out the current ResourceManager subsystem and replace it
> > with something much smaller and faster.
>
> only Strings. I always found it strange to have Embeds and ClassReferences
> in .properties files.
>
> Dirk.
>

RE: Asset / i18n resource management improvements

Posted by Gordon Smith <go...@adobe.com>.
> only Strings. I always found it strange to have Embeds and ClassReferences in .properties files.

Nobody ever needs to localize an embedded image?

- Gordon


-----Original Message-----
From: Dirk Eismann [mailto:bortsen@googlemail.com] 
Sent: Tuesday, June 12, 2012 12:47 PM
To: flex-dev@incubator.apache.org
Subject: Re: Asset / i18n resource management improvements

Hi Alex,

> IMO, something like an "R" class should not be put into the compiler 
> or the IDE.  The compiler should be as framework agnostic as possible.  
> It is probably possible to create a set of classes that do what R does.

maybe I misuderstand you here, but to get compile time code hinting in an IDE and compile time checking for resource accesses, I wonder how something like R should be generated then if not by the compiler?

> How many of you use non-String resources?  A String-only resource 
> system can be so much better optimized than what we have now.  I would 
> love to phase out the current ResourceManager subsystem and replace it 
> with something much smaller and faster.

only Strings. I always found it strange to have Embeds and ClassReferences in .properties files.

Dirk.

Re: Asset / i18n resource management improvements

Posted by Alex Harui <ah...@adobe.com>.


On 6/12/12 12:47 PM, "Dirk Eismann" <bo...@googlemail.com> wrote:

> Hi Alex,
> 
>> IMO, something like an "R" class should not be put into the compiler or the
>> IDE.  The compiler should be as framework agnostic as possible.  It is
>> probably possible to create a set of classes that do what R does.
> 
> maybe I misuderstand you here, but to get compile time code hinting in
> an IDE and compile time checking for resource accesses, I wonder how
> something like R should be generated then if not by the compiler?
To me, the most important thing to get right is the run-time implementation.
Once we nail that, someone will figure out how to get you something like
code-hinting.

Fundamentally, IMO, a string-only resource system is a simple lookup table
of a string key to a longer string.  Then for organizational purposes folks
tend to group those keys into bundles.

What we do today is bake classes for these bundles.  Then we install these
classes into a manager at startup time.  And we do that for error strings
you may never see, and Alert labels you hopefully will not see before the
first screen appears.  And the classes are actually quite big compared to
simply embedding a string table in the SWF (or loading the string table at
runtime).   Also, it isn't clear you need a class.  You might be able to use
simple dynamic objects instead.

And if we decide that classes have too much overhead and simply use dynamic
objects, what would then happen to code hinting?  There wouldn't be any
classes to hint.  How would you find spelling errors in the keys?  I'd hate
to see us drag down runtime performance just so you can get code-hinting.  I
think some IDE will someday be smart enough to look at the string tables and
help you get your keys right.


-- 
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui


Re: Asset / i18n resource management improvements

Posted by Dirk Eismann <bo...@googlemail.com>.
Hi Alex,

> IMO, something like an "R" class should not be put into the compiler or the
> IDE.  The compiler should be as framework agnostic as possible.  It is
> probably possible to create a set of classes that do what R does.

maybe I misuderstand you here, but to get compile time code hinting in
an IDE and compile time checking for resource accesses, I wonder how
something like R should be generated then if not by the compiler?

> How many of you use non-String resources?  A String-only resource system can
> be so much better optimized than what we have now.  I would love to phase
> out the current ResourceManager subsystem and replace it with something much
> smaller and faster.

only Strings. I always found it strange to have Embeds and
ClassReferences in .properties files.

Dirk.

Re: Asset / i18n resource management improvements

Posted by Dirk Eismann <bo...@googlemail.com>.
> Dirk, why would this cause inconsistent behavior?

ok, maybe I chose the wrong wording here. Not inconsistent, just different :-)

Anyways, having compiler warning for missing keys sounds good.

Dirk.

Re: Asset / i18n resource management improvements

Posted by Om <bi...@gmail.com>.
> > What I dont get is why we would need a FB/Eclipse plugin if we manage to
> > make these changes to the compiler.  As you example points out, a valid
> > class would be created in the src path.  This would take care of the
> > auto-complete requirements, right?  All IDEs should be able to work with
> > it.
> IMO, something like an "R" class should not be put into the compiler or the
> IDE.  The compiler should be as framework agnostic as possible.  It is
> probably possible to create a set of classes that do what R does.
>
>
Alex, I think I lost you there.  What Dirk is talking about is to have the
compiler auto-generate the class R as part of pre-compilation.  Except that
this class would actually be added to the source path.
What do you mean by 'framework agnostic'?


> My proposal, is to at least show compiler warnings if other locales dont
> > have matching strings for each entry in the 'master' bundle.
>
> having compiler warnings for missing keys sounds good - but this is
> maybe a bit inconsisten with the runtime behaviour:
>
> IIRC, if you compiled the SWF with the locale chain ["en_US", "fr_FR"]
> and at runtime try to get a key from the fr_FR bundle and that key
> does not exist, Flex will try to get the key from the en_US bundle
> (and failing that I think you get an RTE, not sure though). So no
> warning at runtime but a "soft" fallback to the previous locale in the
> locale chain.
>

Dirk, why would this cause inconsistent behavior?  All the compiler warning
would say is that "hey, you dont have the key in your locale: fr_FR whereas
the master locale: en_US has it".  If the developer ignores the warning and
the scenario you mention occurs, it will cause the same exact runtime
behavior.
What the compiler warnings help with is to avoid having to run into a
runtime error to actually realize the error.

Re: Asset / i18n resource management improvements

Posted by Dirk Eismann <bo...@googlemail.com>.
> I think this is a fantastic idea.  I would love to help out.  Every time I
> work with resource bundles, I keep having similar thoughts.  I never took a
> chance to write it out so clearly like you have done.

good to know. Actually, for years (literally) I wanted to improve this
stuff and had such ideas floating around in my head. Now it's about
time to do it.

> What I dont get is why we would need a FB/Eclipse plugin if we manage to
> make these changes to the compiler.  As you example points out, a valid
> class would be created in the src path.  This would take care of the
> auto-complete requirements, right?  All IDEs should be able to work with
> it.

yes. But an additional IDE plugin could help in certain areas, e.g.
when you drag & drop a new image file into the /res/images folder then
Eclipse "dispatches change events" (to speak in Flex/AS speak) which
can be picked up by the plugin to trigger an incremental build inside
Flash Builder.

As of now, the Flash Builder compiler only starts a new compilation
when some source files change (e.g. when you save a source file and
"Build Automatically" is turned on) but not when something outside the
source path changes. An addition Eclipse / FB plugin would just act as
a "watch dog" to tell FB / mxmlc to take over. Also, the plugin could
take care of setting up the required folder structure (/res/images
etc.) and so on. Again, not necessary but helpful for the end user.

But I agree, the code generation should still be done inside the
compiler and not by an additional plugin.

Dirk.

Re: Asset / i18n resource management improvements

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> IIRC, if you compiled the SWF with the locale chain ["en_US", "fr_FR"]
> and at runtime try to get a key from the fr_FR bundle and that key
> does not exist, Flex will try to get the key from the en_US bundle

This is normally done via resource chaining [1] and what you would normally do is create a "en" locale and then an "en_AU", "en_GB" etc locales that only contain what is differences. you then set the resource chain to be ["en_AU", "en"].

I'm fairly certain that Flex expects each locale to be in the from xx_YY and having a locale call "en" is not possible.

So what I propose is:
1. Create path files that show the differences from en_US to en_XX use the patch/diff format and place these in SVN.
2. When compiling generate the full en_XX local files using the patch files  via ant patch

If something new is added to en_US it will automatically get added to the other english locales, it may not be correct initially but will enough people but it will not break the build or cause a run time error.

Thanks,
Justin

Re: Asset / i18n resource management improvements

Posted by Dirk Eismann <bo...@googlemail.com>.
Hi Om,

> My proposal, is to at least show compiler warnings if other locales dont
> have matching strings for each entry in the 'master' bundle.

having compiler warnings for missing keys sounds good - but this is
maybe a bit inconsisten with the runtime behaviour:

IIRC, if you compiled the SWF with the locale chain ["en_US", "fr_FR"]
and at runtime try to get a key from the fr_FR bundle and that key
does not exist, Flex will try to get the key from the en_US bundle
(and failing that I think you get an RTE, not sure though). So no
warning at runtime but a "soft" fallback to the previous locale in the
locale chain.

Dirk.

Re: Asset / i18n resource management improvements

Posted by Om <bi...@gmail.com>.
One feature I would like added is to assign a master resource file.  I have
had scenarios where I start out with en_US and get other locales created by
manually copying a bundle or use the copylocale util.  But once I start
adding new strings to en_US, the other bundles have to be manually kept in
sync.  This becomes too tedious very quickly.

My proposal, is to at least show compiler warnings if other locales dont
have matching strings for each entry in the 'master' bundle.

And master bundle is something we can set as a compiler option.

Thoughts?

On Tue, Jun 12, 2012 at 11:47 AM, Om <bi...@gmail.com> wrote:

> Dirk,
>
> I think this is a fantastic idea.  I would love to help out.  Every time I
> work with resource bundles, I keep having similar thoughts.  I never took a
> chance to write it out so clearly like you have done.
>
> What I dont get is why we would need a FB/Eclipse plugin if we manage to
> make these changes to the compiler.  As you example points out, a valid
> class would be created in the src path.  This would take care of the
> auto-complete requirements, right?  All IDEs should be able to work with
> it.
>
> Look into FTML for that, it's already built in native for Flex... and much
>> more.
>>
>
> Rich,
>
> Can you please elaborate?  Googling "FTML for Flex" is not yielding any
> relevant results.
>
> Thanks,
> Om
>
>
> On Tue, Jun 12, 2012 at 6:27 AM, Dirk Eismann <bo...@googlemail.com>wrote:
>
>> I'm currently experimenting on how to improve resource management in
>> future Apache Flex versions.
>>
>> It all started when I wanted to mimic the Android IDE (ADT) behavior
>> where ADT automatically creates a class R with static accessors for
>> project resources. E.g. a default Android project has a /src and a
>> /res folder. If you put a foo.jpg into the /res/drawable folder, the
>> ADT creates R.drawable.foo that can be referred to in your code (where
>> foo is actually a int that's used for resource loading at runtime,
>> more info here [1])
>>
>> So I jumped in and created a plugin for Eclipse / Flash Builder that
>> does the same by autogenerating a R.as class with static fields that
>> are used to [Embed] image assets. As soon as you drop images into
>> /res/images inside of a FB project, the R.as class gets updated etc.
>> This happens before the mxmlc compiler starts a compilation run, so
>> you can do this in your code
>>
>> <s:Image source="{R.images.foo}"/>
>>
>> This works pretty nicely, although as of now it's only working in FB /
>> Eclipse, not with CLI builds (yet) [2]
>>
>> The next thing on my list was to improve ResourceBundle / i18n
>> handling a bit. I'm too tired to use ResourceManager.getInstance or
>> resourceManager.getString("foo", "bar") all the way which is annoying
>> to type and error prone. Would be much nicer to have code hinting here
>> as well. Ideally, I'd like to do
>>
>>  <s:Label text="{R.bundles.myBundle.foo}"/>
>>
>> which would get the value of the key "foo" from ResourceBundle
>> "myBundle". Another way would be to have a class B (for Bundles) which
>> is even less typing
>>
>>  <s:Label text="{B.myBundle.foo}"/>
>>
>> or something like this.The general idea is to avoid too much typing
>> and taking advantage of what an IDE offers you in terms of code
>> hinting.
>>
>> The nice side effect of this "less code to type" approach is that you
>> get "less errors that will happen" as well since all asset / resource
>> accesses are checked by the compiler.
>>
>> Currently I have a few ideas and things I would like to implement:
>>
>> 1) envision how a default project layout for a Flex project could look
>> like. As of now a default project has a /src folder. Maybe we can
>> agree that it's a good idea to put place assets into an /assets or
>> /resources folder. This would be the default path that is used for
>> automatic asset / bundle transformation and code generation
>>
>> 2) create a compiler extension for mxmlc or a patched version of the
>> flex2.compiler.i18n.I18nCompiler that automatically generates / emits
>> code for the R class and modifying the code that gets generated for
>> the mx.resource.ResourceBundle sublasses without breaking backwards
>> compatibility (so you can still do @Resource or
>> resourceManager.getString())
>>
>> 3) create a Ecipse / FB plugin that uses the "rules" from 1) and the
>> compiler extension from 2) to streamline this in the IDE (as of now I
>> am an FB / Eclipse user so I can only provide Elcipse plugin know-how,
>> I have not yet done anything with IntelliJ or any other Flex IDE)
>>
>> So... what do you think? I would also like to know what other people
>> have in mind concerning asset / resource bundle management, maybe we
>> can team up?
>>
>> Cheers,
>> Dirk.
>>
>> [1] http://developer.android.com/guide/topics/resources/index.html
>> [2] https://plus.google.com/u/0/111304077092175055051/posts/St8TkR4DFLY
>>
>
>

Re: Asset / i18n resource management improvements

Posted by Alex Harui <ah...@adobe.com>.


On 6/12/12 11:47 AM, "Om" <bi...@gmail.com> wrote:

> Dirk,
> 
> I think this is a fantastic idea.  I would love to help out.  Every time I
> work with resource bundles, I keep having similar thoughts.  I never took a
> chance to write it out so clearly like you have done.
> 
> What I dont get is why we would need a FB/Eclipse plugin if we manage to
> make these changes to the compiler.  As you example points out, a valid
> class would be created in the src path.  This would take care of the
> auto-complete requirements, right?  All IDEs should be able to work with
> it.
IMO, something like an "R" class should not be put into the compiler or the
IDE.  The compiler should be as framework agnostic as possible.  It is
probably possible to create a set of classes that do what R does.

> 
> On Tue, Jun 12, 2012 at 6:27 AM, Dirk Eismann <bo...@googlemail.com>wrote:
> 
>> I'm currently experimenting on how to improve resource management in
>> future Apache Flex versions.>>
>> 
>> So... what do you think? I would also like to know what other people
>> have in mind concerning asset / resource bundle management, maybe we
>> can team up?
>> 
How many of you use non-String resources?  A String-only resource system can
be so much better optimized than what we have now.  I would love to phase
out the current ResourceManager subsystem and replace it with something much
smaller and faster.

-- 
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui


Re: Asset / i18n resource management improvements

Posted by Om <bi...@gmail.com>.
Dirk,

I think this is a fantastic idea.  I would love to help out.  Every time I
work with resource bundles, I keep having similar thoughts.  I never took a
chance to write it out so clearly like you have done.

What I dont get is why we would need a FB/Eclipse plugin if we manage to
make these changes to the compiler.  As you example points out, a valid
class would be created in the src path.  This would take care of the
auto-complete requirements, right?  All IDEs should be able to work with
it.

Look into FTML for that, it's already built in native for Flex... and much
> more.
>

Rich,

Can you please elaborate?  Googling "FTML for Flex" is not yielding any
relevant results.

Thanks,
Om

On Tue, Jun 12, 2012 at 6:27 AM, Dirk Eismann <bo...@googlemail.com>wrote:

> I'm currently experimenting on how to improve resource management in
> future Apache Flex versions.
>
> It all started when I wanted to mimic the Android IDE (ADT) behavior
> where ADT automatically creates a class R with static accessors for
> project resources. E.g. a default Android project has a /src and a
> /res folder. If you put a foo.jpg into the /res/drawable folder, the
> ADT creates R.drawable.foo that can be referred to in your code (where
> foo is actually a int that's used for resource loading at runtime,
> more info here [1])
>
> So I jumped in and created a plugin for Eclipse / Flash Builder that
> does the same by autogenerating a R.as class with static fields that
> are used to [Embed] image assets. As soon as you drop images into
> /res/images inside of a FB project, the R.as class gets updated etc.
> This happens before the mxmlc compiler starts a compilation run, so
> you can do this in your code
>
> <s:Image source="{R.images.foo}"/>
>
> This works pretty nicely, although as of now it's only working in FB /
> Eclipse, not with CLI builds (yet) [2]
>
> The next thing on my list was to improve ResourceBundle / i18n
> handling a bit. I'm too tired to use ResourceManager.getInstance or
> resourceManager.getString("foo", "bar") all the way which is annoying
> to type and error prone. Would be much nicer to have code hinting here
> as well. Ideally, I'd like to do
>
>  <s:Label text="{R.bundles.myBundle.foo}"/>
>
> which would get the value of the key "foo" from ResourceBundle
> "myBundle". Another way would be to have a class B (for Bundles) which
> is even less typing
>
>  <s:Label text="{B.myBundle.foo}"/>
>
> or something like this.The general idea is to avoid too much typing
> and taking advantage of what an IDE offers you in terms of code
> hinting.
>
> The nice side effect of this "less code to type" approach is that you
> get "less errors that will happen" as well since all asset / resource
> accesses are checked by the compiler.
>
> Currently I have a few ideas and things I would like to implement:
>
> 1) envision how a default project layout for a Flex project could look
> like. As of now a default project has a /src folder. Maybe we can
> agree that it's a good idea to put place assets into an /assets or
> /resources folder. This would be the default path that is used for
> automatic asset / bundle transformation and code generation
>
> 2) create a compiler extension for mxmlc or a patched version of the
> flex2.compiler.i18n.I18nCompiler that automatically generates / emits
> code for the R class and modifying the code that gets generated for
> the mx.resource.ResourceBundle sublasses without breaking backwards
> compatibility (so you can still do @Resource or
> resourceManager.getString())
>
> 3) create a Ecipse / FB plugin that uses the "rules" from 1) and the
> compiler extension from 2) to streamline this in the IDE (as of now I
> am an FB / Eclipse user so I can only provide Elcipse plugin know-how,
> I have not yet done anything with IntelliJ or any other Flex IDE)
>
> So... what do you think? I would also like to know what other people
> have in mind concerning asset / resource bundle management, maybe we
> can team up?
>
> Cheers,
> Dirk.
>
> [1] http://developer.android.com/guide/topics/resources/index.html
> [2] https://plus.google.com/u/0/111304077092175055051/posts/St8TkR4DFLY
>

Re: Asset / i18n resource management improvements

Posted by "Mr. Rich" <mr...@gmail.com>.
Look into FTML for that, it's already built in native for Flex... and much
more.
On Jun 12, 2012 9:27 AM, "Dirk Eismann" <bo...@googlemail.com> wrote:

> I'm currently experimenting on how to improve resource management in
> future Apache Flex versions.
>
> It all started when I wanted to mimic the Android IDE (ADT) behavior
> where ADT automatically creates a class R with static accessors for
> project resources. E.g. a default Android project has a /src and a
> /res folder. If you put a foo.jpg into the /res/drawable folder, the
> ADT creates R.drawable.foo that can be referred to in your code (where
> foo is actually a int that's used for resource loading at runtime,
> more info here [1])
>
> So I jumped in and created a plugin for Eclipse / Flash Builder that
> does the same by autogenerating a R.as class with static fields that
> are used to [Embed] image assets. As soon as you drop images into
> /res/images inside of a FB project, the R.as class gets updated etc.
> This happens before the mxmlc compiler starts a compilation run, so
> you can do this in your code
>
> <s:Image source="{R.images.foo}"/>
>
> This works pretty nicely, although as of now it's only working in FB /
> Eclipse, not with CLI builds (yet) [2]
>
> The next thing on my list was to improve ResourceBundle / i18n
> handling a bit. I'm too tired to use ResourceManager.getInstance or
> resourceManager.getString("foo", "bar") all the way which is annoying
> to type and error prone. Would be much nicer to have code hinting here
> as well. Ideally, I'd like to do
>
>  <s:Label text="{R.bundles.myBundle.foo}"/>
>
> which would get the value of the key "foo" from ResourceBundle
> "myBundle". Another way would be to have a class B (for Bundles) which
> is even less typing
>
>  <s:Label text="{B.myBundle.foo}"/>
>
> or something like this.The general idea is to avoid too much typing
> and taking advantage of what an IDE offers you in terms of code
> hinting.
>
> The nice side effect of this "less code to type" approach is that you
> get "less errors that will happen" as well since all asset / resource
> accesses are checked by the compiler.
>
> Currently I have a few ideas and things I would like to implement:
>
> 1) envision how a default project layout for a Flex project could look
> like. As of now a default project has a /src folder. Maybe we can
> agree that it's a good idea to put place assets into an /assets or
> /resources folder. This would be the default path that is used for
> automatic asset / bundle transformation and code generation
>
> 2) create a compiler extension for mxmlc or a patched version of the
> flex2.compiler.i18n.I18nCompiler that automatically generates / emits
> code for the R class and modifying the code that gets generated for
> the mx.resource.ResourceBundle sublasses without breaking backwards
> compatibility (so you can still do @Resource or
> resourceManager.getString())
>
> 3) create a Ecipse / FB plugin that uses the "rules" from 1) and the
> compiler extension from 2) to streamline this in the IDE (as of now I
> am an FB / Eclipse user so I can only provide Elcipse plugin know-how,
> I have not yet done anything with IntelliJ or any other Flex IDE)
>
> So... what do you think? I would also like to know what other people
> have in mind concerning asset / resource bundle management, maybe we
> can team up?
>
> Cheers,
> Dirk.
>
> [1] http://developer.android.com/guide/topics/resources/index.html
> [2] https://plus.google.com/u/0/111304077092175055051/posts/St8TkR4DFLY
>