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 escaping linked translations #248

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Fasust
Copy link

@Fasust Fasust commented Sep 30, 2024

I ran into an issue with linking translations and having them immediately followed by another word character.

Example:

{
  "common": {
    "nbsp": "\u00a0",
    "@nbsp": "No-Break Space https://unicode-explorer.com/c/00A0",
  },
   "message": "10@:common.nbspDays"
}

Message is linking to @:common.nbsp, but the link will be interpreted as @:common.nbspDays which is invalid.
My PR adds the option to escape linked translations:

{
  "common": {
    "nbsp": "\u00a0",
    "@nbsp": "No-Break Space https://unicode-explorer.com/c/00A0",
  },
   "message": "10@:common.nbsp:@Days"
}

@Tienisto
Copy link
Member

Hi, thanks for the PR!
Do you know how other solutions handle this issue? This feature is inspired by linked translations of easy_localization but they probably followed the structure of Vue i18n.

I think it is better to handle it similar to how Dart handles interpolation ($ for greedy interpolation, ${} for edge cases).
Therefore, the following syntax might be safer to use (e.g. when somebody wants to have an actual @ in the string right after the linked translation):

{
  "message": "10@:{common.nbsp}Days"
}

Here, I surrounded the path with {...}
Let me know how you think about this. It might be a little bit more difficult to implement though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants