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

feat: Add 'most-similar-by-key' mode for TargetPickingStrategy #758

Merged
merged 5 commits into from
Aug 27, 2023

Conversation

johanninos
Copy link
Contributor

@johanninos johanninos commented Apr 28, 2022

A Vue project might have the following file structure:
locales

  ├── en
  |   ├── common.json
  |   ├── buttons.json
  |   ├── ...
  |   └── index.ts
  ├── de-DE
  |   ├── common.json
  |   ├── buttons.json
  |   ├── ...
  |   └── index.ts
  └── <country-code>
      ├── common.json
      ├── buttons.json
      ├── ...
  |   └── index.ts
  // locales/en/index.ts
  import buttons from 'bottons.json';
  ......

  export default {
      common,
      buttons,
  }
   // in components
   {{ t('buttons.someType.someName') }}
   {{ t('common.someType.someName') }}

In the code, we can use t('buttons.someType.someName') or t('common.someType.someName') in the components to retrieve translated text. However, it is inconvenient to have to choose the file to save every time.

I mentioned the most-similar mode, but noted that it is not suitable because common.xxx can be in any folder path.

I considered extracting the namespace to determine the target file, but found that namespaces can be complicated. For example, the namespaces configuration is ['{locale}/{namespaces}.*', 'zh-cn/hello/world/messages.json', 'hello/world/messages', 'zh-cn'].
So, you found an easier and more flexible way to resolve it by matching the most similar key. The logic is the same as most-similar, except that the findBestMatchFile argument is changed from fromPath to keypath.

When using common.*, it will match the common.json file.
When using buttons.*, it will match the buttons.json file.

I hope this PR can be merged soon, as it can solve my problem and save development time.
Thank you.

@johanninos johanninos changed the title add a most-similar-by-key mode for TargetPickingStrategy feat: Add 'most-similar-by-key' mode for TargetPickingStrategy Apr 28, 2022
@johanninos johanninos closed this Apr 28, 2022
@johanninos johanninos reopened this Jul 3, 2023
@terales terales merged commit 93e2c46 into lokalise:main Aug 27, 2023
3 checks passed
huacnlee pushed a commit to huacnlee/i18n-ally that referenced this pull request Aug 28, 2023
…ise#758)

* add a most-similar-by-key mode for TargetPickingStrategy

* math prefix of key

* math prefix of key

* Empty commit to trigger CI

---------

Co-authored-by: Joe <[email protected]>
Co-authored-by: Alex Terehov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants