Multi Language Support & Label Customization
 
Multi language support is one of the big advantages of the framework. Any new language can easily be added to the solution. You can just switch among languages. Right-To-Left languages are also supported. You also may configure the fall back language. Words which were not translated yet will be replaced by the fall back language.
 
We have to differentiate between the static text (fields and messages) and multi language business data which is managed by the users. 
Label & Message Customization
 
The labels and messages for the static text are stored in the database in the resource table XAppResources and can be easily changed there. The Module Manager module gives the administrator the possibility to edit existing labels and messages or add new labels and messages.

If you are creating a new view or if there is a new label you want to be translated when switching the language then you just have to add "{Translate MyNewField}" in the XAML view assuming MyNewField is the name of your field. E.g. … Content="{Translate fiAccountNoL}" To use the translator for a message P2Translator.GetResource("fiAccountNotSaved") should be used in the code.
Then you have to add one row for each language for this field to the XAppResources table.

If you want to use the multilingual functionalities for a message, just use P2Translator.GetResource("MyNewMessage") and add one row for each language for MyNewMessage to the XAppResources table.
 
 
Multi Language Business Fields
 
If you have a field or a combo box which has to adapt itself to the used language then you have to add a field for each language used in your application.
E.g. if you want to save the name of your customers in three languages, English, Greek and Arabic, then you need to add three columns in your table: CustomerNameEn, CustomerNameEl, CustomerNameAr. 
 
The user also has to have a possibility to add and change the names, so there must be a view where all three customer names can be edited.

To show the CustomerName depending on the selected language you have to define a new member in the Business Entity class. For the example above you have to add the following code in the Computed Properties region:

public string CustomerNameCur

{

get

{

switch (P2Translator.CultureLanguageFU)

{

case "En":

{ return this.CustomerNameEn; }

case "De":

{ return this.CustomerNameDe; }

case "Ar":

{ return this.CustomerNameAr; }

default:

return this.CustomerNameEn;

}

}

set

{...}

}

 
 
If you use the customer name in a combo box then you have to include the following code in the xaml view in addition to the declation of the CustomerNameCur member as shown above:

<ComboBox DisplayMemberPath="CustomerNameCur" .../> 

 
Fallback Language
 
The GetResource and Translate methods are defined in the P2Translator class in the P2.Cuberry.Framework.Helper assembly and they do the following: 
  • Access the XAppConfigResources table and search the label name in the current module in the selected language.
     
  • If no entry is found then the fallback language is taken which is defined in the XAppConfig table:

    ConfigID   ValueType  ConfigName ConfigValue 
     5  string  FallbackLanguage  En
  • If again no entry was found, then the system fallback language is taken which is defined in the code:
     

    public static string FallbackLanguageFU

    {

    get

    {

    string lang = ConfigurationSetUp.GetAppConfigValue("FallbackLanguage");

    if (string.IsNullOrEmpty(lang))

    lang = "En";

    return lang;

    }

    }

     
  • As a last choice the field name is shown 
When creating a new module or a new view it is recommended to make sure that at least all English labels are included.
 
Some labels and messages are used in the main application view, so they are not connected to one module. Therefore you will find them in the xAppResource table with an empty module name field.