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

Output the files in which a string is found in customValueTemplate #970

Merged
merged 1 commit into from Feb 26, 2024

Conversation

pxpeterxu
Copy link
Contributor

@pxpeterxu pxpeterxu commented Feb 1, 2024

Why am I submitting this PR

Thanks again for the great framework and maintenance @karellm -- we've now translated our Wanderlog trip planner mobile app to French with help from this!

As a part of the process, we realized that sometimes, translators can benefit with some extra context about the strings they're translating: e.g., it matters if a string like "Round trip" comes from a file called FlightSearchInput.tsx. The customValueTemplates have been really helpful with other annotations, so we thought it'd be helpful to extend it so that we can put:

{
  locales: [SupportedLocale.en],
  output: 'forTranslators.json',
  customValueTemplate: {
    message: '${defaultValue}',
    filePaths: '${filePaths}',
  },
}

Changes

  • Add an extra special-case for the customValueTemplate handling (similar to defaultValue) which will also substitute in the paths of all the files where we found a particular key
  • Add tests to verify this behavior works properly with multiple files

Note: to make this easier to merge, I also invited you to have write access to our repository.

Example output when run on our codebase:

{
  "Perfect for road trips and saving $$$ on gas! Get the best route auto-rearranged.": {
    "filePaths": [
      "/Users/peter/Code/itineraries/client/templates/LandingPage/LandingPageProFeatureTiles.tsx"
    ]
  },
  "See more": {
    "filePaths": [
      "/Users/peter/Code/itineraries/client/templates/LandingPage/LandingPageReview.tsx",
      "/Users/peter/Code/itineraries/client/templates/LandingPage/LandingPageTestimonial.tsx"
    ]
  }
}

Does it fix an existing ticket?

No

Checklist

  • only relevant code is changed (make a diff before you submit the PR)
  • tests are included and pass: yarn test (see details here)
  • documentation is changed or added

@karellm karellm merged commit d5ed3a0 into i18next:master Feb 26, 2024
5 checks passed
@karellm
Copy link
Member

karellm commented Feb 26, 2024

Thanks @pxpeterxu ! This seems like a valuable addition. I will make it to 8.13.0

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.

None yet

2 participants