Re: advice on localizing specific attributes from XML file
Re: advice on localizing specific attributes from XML file
- Subject: Re: advice on localizing specific attributes from XML file
- From: "Steve Shepard" <email@hidden>
- Date: Sat, 8 Sep 2007 12:12:54 -0700
Another approach would be to use DTD entities. This is how Mozilla
localizes XUL (XML) files.
The Blocks XML file would look something like this:
<menu id="com.blocks.BUserInterface.menus.main">
<menuitem title="" id="application"
submenu="com.blocks.BUserInterface.menus.main.application" />
<menuitem title="&menuFile.label;" id="file"
submenu="com.blocks.BUserInterface.menus.main.file" />
<menuitem title="&menuEdit.label;" id="edit"
submenu="com.blocks.BUserInterface.menus.main.edit" />
<menuitem title="&menuWindow.label;" id="window"
submenu="com.blocks.BUserInterface.menus.main.window" />
<menuitem title="&menuHelp.label;" id="help"
submenu="com.blocks.BUserInterface.menus.main.help" />
</menu>
And the entity definitions in the English DTD would look like this:
<!ENTITY menuFile.label "File">
<!ENTITY menuEdit.label "Edit">
<!ENTITY menuWindow.label "Window">
<!ENTITY menuHelp.label "Help">
For more information, check out the following:
http://books.mozdev.org/html/mozilla-chp-11.html
http://books.mozdev.org/html/mozilla-chp-11-sect-2.html#mozilla-CHP-11-SECT-2.1
-Steve
On 9/6/07, Jesse Grosjean <email@hidden> wrote:
> I"m working on a new version of my Blocks plugin framework. This
> version will allow for a lot more configuration info to be declared
> in the plugin.xml configuration files. And some of that information
> will need to be localized. For instance here's some markup that
> defines a main menu:
>
> <menu id="com.blocks.BUserInterface.menus.main">
> <menuitem title="" id="application"
> submenu="com.blocks.BUserInterface.menus.main.application" />
> <menuitem title="File" id="file"
> submenu="com.blocks.BUserInterface.menus.main.file" />
> <menuitem title="Edit" id="edit"
> submenu="com.blocks.BUserInterface.menus.main.edit" />
> <menuitem title="Window" id="window"
> submenu="com.blocks.BUserInterface.menus.main.window" />
> <menuitem title="Help" id="help"
> submenu="com.blocks.BUserInterface.menus.main.help" />
> </menu>
>
> And in this case the File, Edit, Window, and Help titles all need to
> be localized. If I were working in a .m file I would just use
> NSLocalizedString, but I'm not sure what the best way to handle
> string localization in an XML file is.
>
> Basically I want something that will work like NSLocalizedString(),
> but has friendlier XML syntax. I'm thinking that I might just append
> attribute strings that should be localized with a '%'. So the above
> would turn into:
>
> <menu id="com.blocks.BUserInterface.menus.main">
> <menuitem title="" id="application"
> submenu="com.blocks.BUserInterface.menus.main.application" />
> <menuitem title="%File" id="file"
> submenu="com.blocks.BUserInterface.menus.main.file" />
> <menuitem title="ķit" id="edit"
> submenu="com.blocks.BUserInterface.menus.main.edit" />
> <menuitem title="%Window" id="window"
> submenu="com.blocks.BUserInterface.menus.main.window" />
> <menuitem title="%Help" id="help"
> submenu="com.blocks.BUserInterface.menus.main.help" />
> </menu>
>
> That would make the strings easy to detect when I read them into my
> program, and then I would call [NSBundle localizedStringForKey] on
> the read in values to get the localized values. This seems like it
> would work, but it also means that I'll need to duplicate the
> functionality of genstrings to recognize the new markup that I'm
> using. Not to bad, but a little pain.
>
> Anyway please let me know if this approach seems to make sense, or if
> there are better solutions to the problem that I don't know about. My
> end goal is to make the translation as strait forward and OS X like
> as possible. I think that means that the translation probably
> shouldn't have to know about the XML at all, so just localizing the
> XML files doesn't seem to make sense.
>
> Thanks,
> Jesse
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden