Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More powerful translation system #55

Open
Sv443 opened this issue Mar 19, 2024 · 0 comments
Open

More powerful translation system #55

Sv443 opened this issue Mar 19, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@Sv443
Copy link
Owner

Sv443 commented Mar 19, 2024

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
@Sv443 Sv443 added the enhancement New feature or request label Mar 19, 2024
@Sv443 Sv443 self-assigned this Mar 19, 2024
@Sv443 Sv443 mentioned this issue May 23, 2024
46 tasks
@Sv443 Sv443 added this to the v3.0.0 milestone May 28, 2024
@Sv443 Sv443 mentioned this issue Oct 19, 2024
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant