Difference between revisions of "LocalizedString class"

From Catglobe Wiki
Jump to: navigation, search
Line 26: Line 26:
 
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Description=<nowiki>Get information about this class.</nowiki>}}
 
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Description=<nowiki>Get information about this class.</nowiki>}}
 
}}
 
}}
 +
=== <span style="color:#DF8621">'''Examples'''</span> ===
 +
<span style="color:#DF8621"> Create a new translatable text </span>
 +
<source lang="javascript">
 +
LocalizedString localizedString = new LocalizedString ();
 +
//SetTranslation
 +
localizedString.SetTranslation("en-GB", "En text");
 +
localizedString.SetTranslation("da-DK", "Da text");
 +
//GetTranslation
 +
print(localizedString.GetSpecificTranslation("en-GB"));//En text
 +
print(localizedString.GetSpecificTranslation("da-DK"));//Da text
 +
print(localizedString.GetSpecificTranslation("en-US"));//Empty
 +
print(localizedString.GetTranslation("en-US"));//En text
 +
print(localizedString.GetTranslationForLoggedInUser());//"Da text" if languge of login user is Danish
 +
//RemoveTranslation
 +
localizedString.RemoveTranslation("en-GB");
 +
print(localizedString.GetSpecificTranslation("en-GB"));//Empty
 +
</source>
 +
<span style="color:#DF8621"> Create a new translatable text based on existing dictionary </span>
 +
<source lang="javascript">
 +
Dictionary translation = {
 +
"en-GB":"En text",
 +
"da-DK":"Da text"
 +
};
 +
LocalizedString localizedString = new LocalizedString (translation, "da-DK");
 +
//GetTranslation
 +
print(localizedString.GetSpecificTranslation(""));//Da text
 +
//SetTranslation
 +
localizedString.SetTranslation("","Danish text");
 +
print(localizedString.GetSpecificTranslation(""));//Danish text
 +
</source>

Revision as of 10:24, 13 July 2018

LocalizedString



Represents translation of a string.

Constructors

  • () - Create a new translatable text
  • (Dictionary dictionary "Dictionary with existing values", string defaultIsocode "If given use this isocodes value in the dictionary as the default") - Create a new translatable text based on existing dictionary

Methods

  • string GetSpecificTranslation(string isocode "Isocode for language. Use empty for default text") - Get the translation for given isocode or null
  • string GetTranslation(string isocode "Isocode for language. Use empty for default text") - Get the best matching translation for given isocode
  • string GetTranslationForLoggedInUser() - Get the best matching translation for the current user
  • bool RemoveTranslation(string isocode "Isocode for language. Use empty for default text") - Remove a specific translation
  • Empty SetTranslation(string isocode "Isocode for language. Use empty for default text", string s "New translation") - Set a specific translation
  • string ToString() - The string representation of the object.

Properties

  • string ObjectTypeName { get; } - The name of the type of object.
  • TypeInformation TypeInformation { get; } - Get information about this class.

Examples

Create a new translatable text

LocalizedString localizedString = new LocalizedString ();
//SetTranslation
localizedString.SetTranslation("en-GB", "En text");
localizedString.SetTranslation("da-DK", "Da text");
//GetTranslation
print(localizedString.GetSpecificTranslation("en-GB"));//En text
print(localizedString.GetSpecificTranslation("da-DK"));//Da text
print(localizedString.GetSpecificTranslation("en-US"));//Empty
print(localizedString.GetTranslation("en-US"));//En text
print(localizedString.GetTranslationForLoggedInUser());//"Da text" if languge of login user is Danish
//RemoveTranslation
localizedString.RemoveTranslation("en-GB");
print(localizedString.GetSpecificTranslation("en-GB"));//Empty

Create a new translatable text based on existing dictionary

Dictionary translation = {
	"en-GB":"En text",
	"da-DK":"Da text"	
};
LocalizedString localizedString = new LocalizedString (translation, "da-DK");
//GetTranslation
print(localizedString.GetSpecificTranslation(""));//Da text
//SetTranslation
localizedString.SetTranslation("","Danish text");
print(localizedString.GetSpecificTranslation(""));//Danish text