Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I am developing a multi-language application which supports English and Japanese. But, as everyone might have known, the language structure of these two languages are quite different. For example, when I want to show "Line 1" on a VF page in Japanese, it'd be "1行目"(meaning the first line).

I created a custom label named 'Line'.

Japanese = 行目 and English = Line.

I'm planning to develop the process mentioned above as follows; (The code might not compile. It's just a concept.)

String showString;
String number = '1';
if(UserInfo.getLanguage() =='ja') showString = number + Label.line;
else showString = Lable.line + number;

But I don't want to put an if in my code for every language.

Is there any better ways to solve this problem?

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

This is where String.format comes in play. For example, you could write this:

String errorLine = String.format(Label.error_on_line_x, new string[] { String.valueof(linenumber) });

This way, label might be 'Error on line {0}' in English, and '{0}行目' in Japanese, and it will format correctly in both languages (use the label translation system...).

share|improve this answer
    
Thank you. I just did as you suggested and it works. This is very helpful. :) –  lw29 Jul 8 at 6:29
    
+1 @sfdcfox! :) –  Bachovski Jul 8 at 19:58
add comment

What I would do in this case is create a set of languages that have the number before the label:

Set <String> languagesWithLabelAsSuffix = new Set <String> {'ja', 'XX', 'YY'};

and then check if the user language is one of the above:

String showString;
String number = '1';
if (languagesWithLabelAsSuffix.contains(UserInfo.getLanguage()) == true)
{
    showString = number + Label.line;
}
else
{
    showString = Lable.line + number;
}

Also, for easier maintainability, you can create custom settings where you can store semi-colon separated language initials for those languages, parse that string and store the values in the languagesWithLabelAsSuffix set.

share|improve this answer
    
Thank you for the advice! This is better than my approach. I have never used custom settings before. I'll learn more about it. Must be useful for the future. :] –  lw29 Jul 8 at 6:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.