www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Localizing a D application - best practices?

reply "Cliff" <cliff.s.hudson gmail.com> writes:
Coming from the C# world, all of localization we did was based on 
defining string resource files (XML-formatted source files which 
were translated into C# classes with named-string accessors by 
the build process) that would get included in the final 
application.  For log messages, exception messages (because 
unhandled exceptions could make it to the user in the case of a 
bug) and format strings used for the above we would create a 
string table entry and this file would eventually get localized 
by the appropriate team.

Is there a recommended pattern for applications in D that wish to 
do localization?

Thanks.
Sep 28 2014
next sibling parent "Chris" <wendlec tcd.ie> writes:
On Sunday, 28 September 2014 at 21:29:21 UTC, Cliff wrote:
 Coming from the C# world, all of localization we did was based 
 on defining string resource files (XML-formatted source files 
 which were translated into C# classes with named-string 
 accessors by the build process) that would get included in the 
 final application.  For log messages, exception messages 
 (because unhandled exceptions could make it to the user in the 
 case of a bug) and format strings used for the above we would 
 create a string table entry and this file would eventually get 
 localized by the appropriate team.

 Is there a recommended pattern for applications in D that wish 
 to do localization?

 Thanks.
I don't know. But JSON is very popular in the D community. dub, the package manager uses it for configuration files, I use JSON for the same purpose in my applications. Although the present std.json is not up to current D standards (still?), it is perfectly usable. Alternatively you can have a look at vibe.d's implementation (http://vibed.org/api/vibe.data.json/) which I use in vibe.d apps. I do not recommend XML, not only because it may be overkill for localization, but because the std.xml module should have been put down a long time ago. If you do want to use XML, however, you may have a look at Adam D. Ruppe's dom.d[1][2]. In the D community JSON is usually preferred to XML. [1] https://github.com/adamdruppe/HTML-DOM [2] https://github.com/adamdruppe/arsd
Sep 29 2014
prev sibling parent "Freddy" <Hexagonalstar64 gmail.com> writes:
On Sunday, 28 September 2014 at 21:29:21 UTC, Cliff wrote:
 Coming from the C# world, all of localization we did was based 
 on defining string resource files (XML-formatted source files 
 which were translated into C# classes with named-string 
 accessors by the build process) that would get included in the 
 final application.  For log messages, exception messages 
 (because unhandled exceptions could make it to the user in the 
 case of a bug) and format strings used for the above we would 
 create a string table entry and this file would eventually get 
 localized by the appropriate team.

 Is there a recommended pattern for applications in D that wish 
 to do localization?

 Thanks.
I personally recommend you do this --- void main(){ string name=import("mylang"); } --- and add a folder with mylang with -J . eg: -Jenglish -Jspanish
Sep 29 2014