Page MenuHomePhorge

Develop the translation strategy for strings on the client `JX` side
Open, Needs TriagePublic

Description

For background, read all of the comments in D25015

In a nutshell - How can we define a string in client-side javascript that we can run through pht in order to get the correct translation of that string?

In the case of D25015 it is the dialog close confirmation string of Form data may have changed. Are you sure you want to close this dialog?

Event Timeline

I think that, from the view model, we should be able to call something like this:

->addFrontendMessages( 'component', array(
 'fooLabel' => pht( "Foo Label" ),
 'error' => pht( "Error! "),
) )

Then, it should automatically injext this JavaScript code to the frontend, like in this way:

window.I18N = window.I18N || {};
window.I18N.component = window.I18N.component || {};
window.I18N.component = {
  fooLabel: "Foo Label",
  error: "Error",
};

Then, from JavaScript you can do:

alert(I18N.componen.fooLabel)

This for base messages