开发者

Problem when concatenating string and a resource value

开发者 https://www.devze.com 2023-02-16 13:28 出处:网络
I\'m having a strange behavior in my .aspx page. I\'m internationalizing some pages, but as I want to keep only entities or value object in my resource I want to have a key-value like:

I'm having a strange behavior in my .aspx page. I'm internationalizing some pages, but as I want to keep only entities or value object in my resource I want to have a key-value like:

(pt-br)
    CITY - Cidade
    STATE - Estado
    ...

But when I list the entities, I want to put the " : " at end. Like:

<asp:Label ID="LabelCity" runat="server" Text="<%$ Resources:Localizacao, CITY %>:"></asp:Label>

But, if I put the " : " after the resource in text property, the page only shows " : ".

My simple solution is put after all definition of label, but I think this too wrong:

<asp:Label ID="LabelCity" runat="server" Text="<%$ Resources:Localizacao, CITY %>"></asp:Label>:

开发者_开发百科Suggestions?


Had the exact same problem and after some searching transformed this

<asp:Label ID="label" runat="server" Text="<%$ Resources: Resources, color %>" />:

to this:

<asp:Label ID="label" runat="server">
    <%= Resources.Resources.color + ":"%>
</asp:Label>


You named this correctly: the concatenation. The problem is, Concatenation is one of the most serious (as in high severity) i18n defect. Instead of doing what you do, I would advise you to put whole strings (or in the worst case scenario strings with placeholders) into resource files, even you have to duplicate resources (these duplicated resources might be translated in different way depending on a context).

Let me give you an example: back when I was in L10n Team, we had a console with multiple pages, each page had a title which was "Something Policy", i.e. "Firewall Policy", "Antivirus and Antispyware Policy". Somebody thought it is a good idea to save some precious bits and simply concatenated the title together:

String title = Resources.getString("Firewall") + "<b>" + Resources.getString("Policy") + "</b>";

The only problem we had is correct Polish translation sounds like "Polityka zapory ogniowej", that is "Policy" comes first. In reality, we had it translated as "Zapora ogniowa Polityka" which is nowhere near the correct translation (notice that translation of "Firewall" should be genitive... Translator had no clue what he is translating, thus the translation. And it couldn't be fixed as we were unable to re-order the sentence.

The fix required externalizing the whole string, so actually all the good intentions of original developer went to pave the hell.

If you still reading this, please keep in mind, that all colons in French language must be preceded by space (that's just their rule). Re-using the same translations in order to build multiple sentences might disallow that...


Expressions (the <%$) are a set syntax so it is a all or nothing if you want to use an expression there. You can do what you have suggested or set the values from the code behind as alternatives.

However, I think your character should be in your resource file. Are all languages going to use that same character? Will that work for right-to-left lanugages?

0

精彩评论

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