Skip to content

Commit

Permalink
feat: new config "i18n-ally.ignoreFiles"
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 27, 2020
1 parent f151918 commit 674618b
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dist
out
node_modules
web_modules
.vscode-test/
*.vsix
*.zip
Expand Down
5 changes: 5 additions & 0 deletions examples/by-features/js-parser-dir/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"i18n-ally.localesPaths": "locales",
"i18n-ally.enabledParsers": ["ts", "js"],
"i18n-ally.ignoreFiles": ["**/index.ts"]
}
21 changes: 21 additions & 0 deletions examples/by-features/js-parser-dir/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<div id="app">
<p>{{ $t('project') }}</p>
<p>{{ $t('hello') }}</p>

<p>{{ $tc('today') }}</p>
<p>{{ $tc('now') }}</p>
</div>
</template>

<script>
export default {
name: 'App',
computed: {
foobar () {
return this.$t('nested.foo.bar')
},
},
}
</script>
3 changes: 3 additions & 0 deletions examples/by-features/js-parser-dir/locales/en/a.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
a: 'A',
}
3 changes: 3 additions & 0 deletions examples/by-features/js-parser-dir/locales/en/b.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
b: 'B',
}
7 changes: 7 additions & 0 deletions examples/by-features/js-parser-dir/locales/en/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import a from './a'
import b from './b'

export default {
...a,
...b,
}
3 changes: 3 additions & 0 deletions examples/by-features/js-parser-dir/locales/zh-cn/a.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
a: '甲',
}
3 changes: 3 additions & 0 deletions examples/by-features/js-parser-dir/locales/zh-cn/b.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
b: '乙',
}
7 changes: 7 additions & 0 deletions examples/by-features/js-parser-dir/locales/zh-cn/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import a from './a'
import b from './b'

export default {
...a,
...b,
}
9 changes: 9 additions & 0 deletions examples/by-features/js-parser-dir/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "basic",
"version": "0.1.0",
"private": true,
"dependencies": {
"vue": "^2.6.10",
"vue-i18n": "^8.11.2"
}
}
7 changes: 7 additions & 0 deletions examples/by-features/js-parser-dir/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"allowJs": true
}
}
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"config.enabled_parsers": "Locale file format parsers. By default, It will be handled by activated frameworks",
"config.encoding": "File encoding for reading and writing locale files",
"config.full_reload_on_changed": "Perform a full reload on locale file changes. (for .js/.ts dynamic import)",
"config.ignore_files": "Locale files to ignore on loading. Accepting an array of glob.",
"config.ignored_locales": "Locale codes to ignore",
"config.include_subfolders": "Search recursively inside locale directories",
"config.indent": "Indent space size for locale files",
Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,13 @@
],
"description": "%config.language_tag_system%"
},
"i18n-ally.ignoreFiles":{
"type": "array",
"item": {
"type": "string"
},
"description": "%config.ignore_files%"
},
"i18n-ally.regex.key": {
"type": "string",
"description": "%config.regex_key%"
Expand Down
5 changes: 5 additions & 0 deletions src/core/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class Config {
'disablePathParsing',
'readonly',
'languageTagSystem',
'ignoreFiles',
]

static readonly refreshConfigs = [
Expand Down Expand Up @@ -321,6 +322,10 @@ export class Config {
return this.getConfig<boolean>('disablePathParsing') ?? false
}

static get ignoreFiles() {
return this.getConfig<string[]>('ignoreFiles') ?? []
}

static get keysInUse() {
return this.getConfig<string[]>('keysInUse') || []
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/loaders/LocaleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export class LocaleLoader extends Loader {
onlyDirectories: true,
cwd: dir,
deep: 1,
ignore: Config.ignoreFiles,
})

const total = dirnames.length
Expand Down Expand Up @@ -427,6 +428,7 @@ export class LocaleLoader extends Loader {
ignore: [
'node_modules/**',
'vendors/**',
...Config.ignoreFiles,
],
deep: Config.includeSubfolders ? undefined : 2,
})
Expand Down

0 comments on commit 674618b

Please sign in to comment.