You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a library with an extended syntax for declaring translations.
The goal is not to be as flexible as the other translation libs currently in existence, it's to be as lightweight as possible for userscript usage, while being a step above UserUtils' current, VERY simple translation system.
Requirements:
Interpret certain translations as raw HTML, others as a string (XSS prevention)
Support for named variables (numbered ones are kinda wack for context)
Support for calling predefined actions that result in a string, using passed parameters
Support for nested translations using dot syntax (i.e. generic.buttons.submit)
Example - click to expand
{// regular translation with indexed parameters - like it is right now"example0": "My translation blabla, %0",// translation treated as raw HTML, with a localized URL"example1.0": "[/];My translation blabla <a href=\"local url\">%0</a>",// translation treated as raw HTML, with a variable URL provided by the implementer"example1.1": "[/];My translation blabla <a href=\"%0\">text</a>",// translation with named variables and indexed parameters at the same time"example2": "[$];My translation blabla ${namedVar}, %0",// translation with an action call that results in an arbitrary string"example3": "[@];My translation blabla @{actionName,%0,param2}",// combination of all the above"example4": "[/$@];My translation blabla <a href=\"%0\">${namedVar}</a> @{actionName,%1,param2}"};
Example usage:
tr("example0",["param1"]);tr("example1.0",["anchor text"]);tr("example1.1",["https://example.com"]);tr("example2",{namedVar: "namedVar",0: "param1"});tr.defineAction("actionName",(locale, ...params)=>{return"action result";});tr("example3",["param1"]);tr("example4",{namedVar: "namedVar",0: "https://example.com","1": "param2"});// ^ should support stringified number keys too, because of object & array merging
The text was updated successfully, but these errors were encountered:
Create a library with an extended syntax for declaring translations.
The goal is not to be as flexible as the other translation libs currently in existence, it's to be as lightweight as possible for userscript usage, while being a step above UserUtils' current, VERY simple translation system.
Requirements:
generic.buttons.submit
)Example - click to expand
Example usage:
The text was updated successfully, but these errors were encountered: