开发者

Where to store strings in code, not related to forms, for I18N!

We have a relatively large dotNet application and are wondering where is the best place to store strings in our code that aren't related to forms? We don't want to have tens of un-collapse resx 开发者_如何转开发file being displayed in our application's solution explorer window. Any advice would be appreciated.


Android has an interesting way of doing it - basically having a default directory, then a separate one for each other locale. It looks pretty clean and would be collapsible since they each have their own folders.

Take a look here and see if it's worth modeling your code after:

http://developer.android.com/guide/topics/resources/localization.html


We wrap all strings around i18n() right before output. Most strings are in the code. The i18n function will take the string and context and look it up in a PO file and return the i18n'd result, which I assume you already know that.

A PERL Example

## we have this handy noop function for putting strings into a PO file
i18n_noop('Some string that needs to be i18n','This is the context'); 

## once our string has been captured in the PO file, we can assign it to a scalar variable
my $str = 'Some String that needs to be i18n';

## before printing the str we pass it i18n, this function will take the $str and find the appropriate translation.
print i18n($str);

## we could also do this.  The first argument is the string to be translated.  the second argument is the context.
i18n('Some string that needs to be i18n','This is the context'); 


Typically people tend to create simple source directories for resx files.
One can create LocalizableResources folder and place all translatable resx files there, as well as NonLocalizableResources for non-translatable resx files (if you use them; in sufficiently large project chances are high that you do).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜