Example: Create a Language Bundle
In this example we will create a language bundle to translate our extension into another language. To do that, we make a right-click on"Language Bundles " and select New > Language Bundle. We will call it, "CardExtension ".
{ "phrases": { "D63591732C7F724D8D98B6E5B34B914FFFD6": "Sample Text" } }
It contains an example phrase we can just delete. Next we will create another language bundle called"CardExtension.de ". The"CardExtension " bundle contains our phrases in default language. The"default language " is used if there is no translation for the current language available. The second bundle"CardExtension.de " uses the suffix".de " which stands for german language. So that bundle is used if the current language is german.
Lets take a look at the properties:
phrases
Contains key:phrase pairs to define the different phrases of the bundle. So each phrase needs to have a unique key. The key can be any kind of text as long as it is unique enough. By default UIDs are used for each phrase.
To use a phrase in a UI view you can just use the syntax $$<bundle>.<phrase_uid> like "$$CardExtension.D63591732C7F724D8D98B6E5B34B914FFFD6". That kind of syntax can be used in most places where displayable text can be specified. For Example:
{
"type": "GSLabel",
"text": "$$CardExtension.D63591732C7F724D8D98B6E5B34B914FFFD6",
"frame": [0, 0]
}
So this label will show the phase for key "D63591732C7F724D8D98B6E5B34B914FFFD6" if exists. It first looks if the phrase exists for current language and if that is not the case it will use the default language phrase.
To create new phrases we could just manually add them to our bundle but since that feels a bit uncomfortable after some time, there are two helper-functions doing the most work for us automatically. These two functions are "Insert New String" and "Insert New String (LCS)". We can find these functions in menubar under Tools > Developer Tools or in Extension Editor's toolbar.
Both functions actually doing the same thing but the formatting of the output is different. Lets check how these functions can make our life a little bit easier:
First we need to select a text in one of our views/scene-commands/scripts we want to translate. Next we click on "Insert New String" which will ask us then to enter a bundle name. We will enter the name of our bundle "CardExtension" and click "OK". Two things happened now:
1. Our selected text has been replaced by "$$CardExtension.<uid>" automatically.
2. The selected text has been added to the default language CardExtension bundle and also the UID has been generated automatically.
That saves us a lot of time since we no longer need to generate UIDs by ourselves and add pharses to the bundle manually everytime we want to translate something. We can just use one of the helper-functions. The other helper-function "Insert New String (LCS)" is doing the same but the output is:
lcs('<bundle>.<uid>')
which can be used in scripts and formulas if necessary.