JSONTranslator
Utility function that loads a translator from a folder or a table.
To get translations uploaded.
- Run the game
- On the client, check LocalizationService.GeneratedJSONTable
- Right click > Save as CSV
- Stop the game
- In Studio, go to plugins > "Localization Tools"
- Upload the CSV (update)
Functions
new
JSONTranslator.
new
(
translatorName:
string
,
--
Name of the translator. Used for source.
localeId:
string
,
dataTable:
table
) →
JSONTranslator
Constructs a new JSONTranslator from the given args.
local translator = JSONTranslator.new("MyTranslator", en", {
actions = {
respawn = "Respawn {playerName}";
};
})
print(translator:FormatByKey("actions.respawn"), { playerName = "Quenty"}) --> Respawn Quenty
-- Observing is preferred
maid:GiveTask(translator:ObserveFormatByKey("actions.respawn", {
playerName = RxInstanceUtils.observeProperty(player, "DisplayName");
}):Subscribe(function(text)
print(text) --> "Respawn Quenty"
end)
local translator = JSONTranslator.new(script)
-- assume there is an `en.json` underneath the script with valid JSON.
ObserveFormatByKey
JSONTranslator:
ObserveFormatByKey
(
translationKey:
string
,
translationArgs:
table?
--
May have observables (or convertable to observables) in it.
) →
Observable
<
string
>
Observes the translated value
PromiseFormatByKey
Formats the resulting entry by args.
tip
You should use JSONTranslator.ObserveFormatByKey instead of this to respond to locale changing.
ObserveLocaleId
Observes the current locale id for this translator.
SetEntryValue
JSONTranslator:
SetEntryValue
(
translationKey:
string
,
source:
string
,
context:
string
,
localeId:
string
,
text:
string
) →
(
)
Adds an entry value to the localization table itself. This can be useful for ensuring pseudo localization and/or generating localization values from the game data itself.
GetLocaleId
JSONTranslator:
GetLocaleId
(
) →
string
Gets the current localeId of the translator if it's initialized, or a default if it is not.
GetLocalizationTable
JSONTranslator:
GetLocalizationTable
(
) →
LocalizaitonTable
Gets the localization table the translation is using.
PromiseLoaded
Returns a promise that will resolve once the translator is loaded from the cloud.
FormatByKey
JSONTranslator:
FormatByKey
(
translationKey:
string
,
args:
table?
) →
string
Formats or errors if the cloud translations are not loaded.
tip
You should use JSONTranslator.ObserveFormatByKey instead of this to respond to locale changing.
Destroy
JSONTranslator:
Destroy
(
) →
(
)
Cleans up the translator and deletes the localization table if it exists. Should be called by ServiceBag