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

Allow object as second i18n.getMessage() argument #699

Open
eemeli opened this issue Sep 26, 2024 · 0 comments
Open

Allow object as second i18n.getMessage() argument #699

eemeli opened this issue Sep 26, 2024 · 0 comments
Labels
needs-triage: chrome Chrome needs to assess this issue for the first time needs-triage: firefox Firefox needs to assess this issue for the first time neutral: safari Not opposed or supportive from Safari topic: localization

Comments

@eemeli
Copy link

eemeli commented Sep 26, 2024

Currently, the second substitutions argument of i18n.getMessage() can be a single stringifiable value, or an array thereof. These substitutions may be referenced in a message or the placeholders as $1, $2, etc. To improve the translator experience, the placeholders object allows for these to be mapped to named placeholders in the message:

"notificationContent": {
  "message": "You clicked $URL$.",
  "description": "Tells the user which link they clicked.",
  "placeholders": {
    "url": {
      "content": "$1",
      "example": "https://developer.mozilla.org"
    }
  }
}

We could improve the legibility of the code formatting this message by allowing for substitutions to be an object, so that the above message could be formulated as:

"notificationContent": {
  "message": "You clicked $URL$.",
  "description": "Tells the user which link they clicked.",
  "examples": {
    "url": "https://developer.mozilla.org"
  }
}

and formatted with

browser.i18n.getMessage('notificationContent', { url: 'https://example.com' });

In case there's a concern about mis-identifying a substitution value that's intended to be stringified during formatting as instead an object from which substitution values are to be looked up, handling substitutions like this could be gated behind some flag as introduced in #698 for MF2 support. With that syntax, the above message could be formulated as:

"notificationContent": {
  "message": "You clicked {$url @example=|https://developer.mozilla.org|}.",
  "description": "Tells the user which link they clicked."
}
@github-actions github-actions bot added needs-triage: chrome Chrome needs to assess this issue for the first time needs-triage: firefox Firefox needs to assess this issue for the first time needs-triage: safari Safari needs to assess this issue for the first time labels Sep 26, 2024
@xeenon xeenon added neutral: safari Not opposed or supportive from Safari and removed needs-triage: safari Safari needs to assess this issue for the first time labels Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage: chrome Chrome needs to assess this issue for the first time needs-triage: firefox Firefox needs to assess this issue for the first time neutral: safari Not opposed or supportive from Safari topic: localization
Projects
None yet
Development

No branches or pull requests

3 participants