-
-
Notifications
You must be signed in to change notification settings - Fork 44
feat: support localePattern
option for locale structured with directory
#270
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/fixtures/no-unused-keys/valid/path-locales/locales/en/message.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"hello": "hello world", | ||
"messages": { | ||
"hello": "hi DIO!", | ||
"link": "@:messages.hello" | ||
}, | ||
"hello_dio": "hello underscore DIO!", | ||
"hello {name}": "hello {name}!", | ||
"term": "I accept xxx {0}." | ||
} |
7 changes: 7 additions & 0 deletions
7
tests/fixtures/no-unused-keys/valid/path-locales/locales/ja/message.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
hello: "ハローワールド" | ||
messages: | ||
hello: "こんにちは、DIO!" | ||
link: "@:messages.hello" | ||
hello_dio: "こんにちは、アンダースコア DIO!" | ||
"hello {name}": "こんにちは、{name}!" | ||
term: "私は xxx の{0}に同意します。" |
17 changes: 17 additions & 0 deletions
17
tests/fixtures/no-unused-keys/valid/path-locales/src/App.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<template> | ||
<div id="app"> | ||
<p v-t="'hello_dio'">{{ $t('messages.link') }}</p> | ||
<i18n path="term" tag="label" for="tos"> | ||
<a :href="url" target="_blank">{{ $t('tos') }}</a> | ||
</i18n> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'App', | ||
created() { | ||
this.$i18n.t('hello {name}', { name: 'DIO' }) | ||
} | ||
} | ||
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const $t = () => {} | ||
$t('hello') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello: world |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"hello": "world" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
en: { | ||
hello: "world" | ||
}, | ||
ja: { | ||
hello: "ワールド" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* @author Kazuya Kawaguchi | ||
*/ | ||
import path from 'path' | ||
import assert from 'assert' | ||
import { FileLocaleMessage } from '../../../lib/utils/locale-messages' | ||
|
||
describe('FileLocaleMessage', () => { | ||
describe('localeKey: "file"', () => { | ||
it('locales should be resolved', () => { | ||
const testFilePath = path.resolve( | ||
__dirname, | ||
'../../fixtures/utils/locale-messages/locales/en.yaml' | ||
) | ||
const messages = new FileLocaleMessage({ | ||
fullpath: testFilePath, | ||
localeKey: 'file' | ||
}) | ||
assert.deepStrictEqual(messages.locales, ['en']) | ||
}) | ||
}) | ||
|
||
describe('localeKey: "path"', () => { | ||
it('locales should be resolved', () => { | ||
const testFilePath = path.resolve( | ||
__dirname, | ||
'../../fixtures/utils/locale-messages/locales/en/message.json' | ||
) | ||
const messages = new FileLocaleMessage({ | ||
fullpath: testFilePath, | ||
localeKey: 'path', | ||
localePattern: /^.*\/(?<locale>[A-Za-z0-9-_]+)\/.*\.(json5?|ya?ml)$/ | ||
}) | ||
assert.deepStrictEqual(messages.locales, ['en']) | ||
}) | ||
}) | ||
|
||
describe('localeKey: "key"', () => { | ||
it('locales should be resolved', () => { | ||
const testFilePath = path.resolve( | ||
__dirname, | ||
'../../fixtures/utils/locale-messages/locales/message.json5' | ||
) | ||
const messages = new FileLocaleMessage({ | ||
fullpath: testFilePath, | ||
localeKey: 'key' | ||
}) | ||
assert.deepStrictEqual(messages.locales, ['en', 'ja']) | ||
}) | ||
}) | ||
}) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regular expressions cannot be serialized to JSON, so users can only use
.eslintrc.js
style configurations. Could you change it to acceptstring | RegExp
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, Indeed 😅
we have to support cases in other formats but
.eslintrc.js
, such as.eslintrc.yaml
.