feat: Add 'most-similar-by-key' mode for TargetPickingStrategy #758
+27
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A Vue project might have the following file structure:
locales
In the code, we can use
t('buttons.someType.someName')
ort('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 becausecommon.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 thefindBestMatchFile
argument is changed fromfromPath
tokeypath
.When using
common.*
, it will match thecommon.json
file.When using
buttons.*
, it will match thebuttons.json
file.I hope this PR can be merged soon, as it can solve my problem and save development time.
Thank you.