InstanceLocaleLoader
Owns the lazy per-locale loading state for an instance-decoded JSONTranslator (a folder of per-locale JSON StringValues / ModuleScripts): which locales are available, which have already been loaded, and the accumulated entry lookup.
Decodes and writes a locale's entries to the TranslatorService only the first time that locale is needed. Registered as a service by the JSONTranslator that owns it.
The locale files are reached through a TemplateProvider rather than off the folder directly. On a live server that keeps them from replicating to every client at join -- a game with a dozen languages otherwise ships all of them to a player who reads one -- and each file is fetched on demand instead. Off a live server the provider resolves them locally and synchronously, so nothing about loading changes there.
One file per locale. A second file resolving to a locale the provider already knows is warned about and ignored, since the provider keys templates by name.
Functions
new
InstanceLocaleLoader.new(translatorName: string,sourceLocaleId: string,--
always loaded, the fallback for every key
) → InstanceLocaleLoaderConstructs a new InstanceLocaleLoader. Register it on the ServiceBag that provides the TranslatorService its writes land on -- it pulls in a TemplateProvider of its own, so the standard initialization chain has to reach it.
Init
Initializes the loader. Should be done via ServiceBag.
LoadSourceLocale
Loads the source locale. Always call this first -- it establishes the Source/Context that other locales' values merge onto, and it is the ultimate fallback for every key.
PromiseSourceLocale
Resolves once the source locale's file has been fetched, decoded, and queued onto the TranslatorService. This is what makes a synchronous read (JSONTranslator.FormatByKey) safe: on a live client the file arrives over the network, so there is a window at boot where the fallback for every key is simply not here yet.
LoadAllLocales
Loads every available locale file. Used off the client, where there is no single target locale to narrow to.
PromiseAllLocales
See InstanceLocaleLoader.LoadAllLocales. Resolves once every locale known at the time of the call has landed.
LoadLocale
InstanceLocaleLoader.LoadLocale(localeId: string--
the target locale
) → ()
Loads every available locale file that shares the target's language (e.g. for "es-mx":
both es and es-mx; for "fr-fr": every fr-* file), so a regional player gets the
universal-language strings and same-language siblings as fallbacks before dropping to
the source. The source locale is ensured first. Idempotent -- a file already loaded is
never fetched, decoded, or written again -- and returns nothing, since the caller does
not (and should not) care which files it touched.
PromiseLoadLocale
See InstanceLocaleLoader.LoadLocale. Resolves once the files known to match the target at the time of the call have landed. Files that replicate in later are still loaded -- the request is remembered -- but this promise does not wait for them, since there is no point at which the set is known to be complete.