@@ -31,6 +31,7 @@ import SdkConfig from "./SdkConfig";
3131
3232// @ts -ignore - $webapp is a webpack resolve alias pointing to the output directory, see webpack config
3333import webpackLangJsonUrl from "$webapp/i18n/languages.json" ;
34+ import { ModuleRunner } from "./modules/ModuleRunner" ;
3435
3536const i18nFolder = 'i18n/' ;
3637
@@ -606,15 +607,40 @@ export class CustomTranslationOptions {
606607 }
607608}
608609
610+ function doRegisterTranslations ( customTranslations : ICustomTranslations ) {
611+ // We convert the operator-friendly version into something counterpart can
612+ // consume.
613+ const langs : {
614+ // same structure, just flipped key order
615+ [ lang : string ] : {
616+ [ str : string ] : string ;
617+ } ;
618+ } = { } ;
619+ for ( const [ str , translations ] of Object . entries ( customTranslations ) ) {
620+ for ( const [ lang , newStr ] of Object . entries ( translations ) ) {
621+ if ( ! langs [ lang ] ) langs [ lang ] = { } ;
622+ langs [ lang ] [ str ] = newStr ;
623+ }
624+ }
625+
626+ // Finally, tell counterpart about our translations
627+ for ( const [ lang , translations ] of Object . entries ( langs ) ) {
628+ counterpart . registerTranslations ( lang , translations ) ;
629+ }
630+ }
631+
609632/**
610- * If a custom translations file is configured, it will be parsed and registered.
611- * If no customization is made, or the file can't be parsed, no action will be
612- * taken.
633+ * Any custom modules with translations to load are parsed first, followed by an
634+ * optionally defined translations file in the config. If no customization is made,
635+ * or the file can't be parsed, no action will be taken.
613636 *
614637 * This function should be called *after* registering other translations data to
615638 * ensure it overrides strings properly.
616639 */
617640export async function registerCustomTranslations ( ) {
641+ const moduleTranslations = ModuleRunner . instance . allTranslations ;
642+ doRegisterTranslations ( moduleTranslations ) ;
643+
618644 const lookupUrl = SdkConfig . get ( ) . custom_translations_url ;
619645 if ( ! lookupUrl ) return ; // easy - nothing to do
620646
@@ -636,25 +662,8 @@ export async function registerCustomTranslations() {
636662 // If the (potentially cached) json is invalid, don't use it.
637663 if ( ! json ) return ;
638664
639- // We convert the operator-friendly version into something counterpart can
640- // consume.
641- const langs : {
642- // same structure, just flipped key order
643- [ lang : string ] : {
644- [ str : string ] : string ;
645- } ;
646- } = { } ;
647- for ( const [ str , translations ] of Object . entries ( json ) ) {
648- for ( const [ lang , newStr ] of Object . entries ( translations ) ) {
649- if ( ! langs [ lang ] ) langs [ lang ] = { } ;
650- langs [ lang ] [ str ] = newStr ;
651- }
652- }
653-
654- // Finally, tell counterpart about our translations
655- for ( const [ lang , translations ] of Object . entries ( langs ) ) {
656- counterpart . registerTranslations ( lang , translations ) ;
657- }
665+ // Finally, register it.
666+ doRegisterTranslations ( json ) ;
658667 } catch ( e ) {
659668 // We consume all exceptions because it's considered non-fatal for custom
660669 // translations to break. Most failures will be during initial development
0 commit comments