Skip to content

Commit

Permalink
Merge pull request #7 from creadigme/feat-i18n-default-ns
Browse files Browse the repository at this point in the history
CLI: support of `--default-ns`
  • Loading branch information
miniben-90 authored Mar 28, 2023
2 parents 8dee963 + 3c4f1be commit e268461
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ npm i @creadigme/au-i18n-audit --save-dev
| --namespace | Namespace | `cart` | false | true
| --namespace-sep | NS separator (default `:`) | `$` | false | false
| --nested-sep | Sub key separator (default `.`) | `~` | false | false
| --default-ns | Default namespace (default `translation` or the first namespace) | `easy` | false | false
| --ignore-keys | Provide the ability to ignore specific keys | `^(shop\|other)\\.` | false | false
| --discovery | Provide the ability to discover i18n keys everywhere (you must provide `--namespace` & `--lang`) | | false | false

Expand Down
4 changes: 4 additions & 0 deletions samples/case_06/i18n/fr/AAAA.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
A: B
C: D
E: F
G: etc
4 changes: 4 additions & 0 deletions samples/case_06/i18n/fr/EASY.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
STOP: Stop
START: Start
PAUSE: Pause
NOT_USED: Another One
18 changes: 18 additions & 0 deletions samples/case_06/src/sample.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<template>

<div class="something else" title.one-time="'PAUSE' & t">?</div>
<div class="something else" title.bind="'START' & t">?</div>
<div class="something else" title.one-time="'START' & t">?</div>
<div class="something else" title.bind="'STOP' & t">?</div>

<div class="something else">${"KEY" & t} : </div>
<div class="something else">${'KEY2' | t} : </div>
<!-- ignore this -->
<div class="something else">${'KEY3'} : </div>


<div class="something else" t="KEY"></div>
<div class="something else" t="KEY2"></div>
<!-- ignore this -->
<div class="something else" tt="KEY3"></div>
</template>
28 changes: 28 additions & 0 deletions samples/case_06/src/sample.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export class Sample3 {
public i18n: any;

/**
*/
public something() {
return this.i18n.t('START');
}

/**
*/
public summoner() {
return this.i18n.tr('STOP');
}

/**
*/
public invocation() {
return this.i18n.tr('MIDDLE');
}

/**
*/
public moon() {
// return true; this.i18n.tr("EASY:MOON");
return true; // this.i18n.tr("EASY:MOON");
}
}
9 changes: 9 additions & 0 deletions src/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ describe('cli', () => {
);
});

it('reporter summary, default ns', async () => {
const res = await testCLIAsync('--src', './samples/case_06/src/', '--i18n', './samples/case_06/i18n', '--default-ns', 'EASY', '--reporter', 'summary');
assert.strictEqual(res.exitCode, 1);
assert.strictEqual(
res.stdout,
`\u001b[1m\u001b[4m\u001b[94m[i18n] @creadigme/au-i18n-audit v${version}.\u001b[39m\u001b[24m\u001b[22m\n\u001b[32m[i18n] 1 languages detected (fr).\u001b[39m\n\u001b[1m\u001b[33m[i18n] 5 keys seems not to be used (maybe server side?).\u001b[39m\u001b[22m\n\u001b[1m\u001b[31m[i18n] 3 keys are not defined.\u001b[39m\u001b[22m\n`
);
});

it('reporter text', async () => {
const res = await testCLIAsync('--src', './samples/case_01/src/', '--i18n', './samples/case_01/i18n', '--reporter', 'text');
assert.strictEqual(res.exitCode, 1);
Expand Down
2 changes: 2 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const optionDefinitions = [
{ name: 'remote-i18n', type: String, multiple: false },
{ name: 'lang', type: String, multiple: true },
{ name: 'namespace', type: String, multiple: true },
{ name: 'default-ns', type: String, multiple: false },
{ name: 'ignore-keys', type: String },
{ name: 'namespace-sep', type: String },
{ name: 'nested-sep', type: String },
Expand Down Expand Up @@ -49,6 +50,7 @@ CLIReporter.cliAsync({
autoDiscovery: options.discovery,
languages: options.lang || [],
namespaces: options.namespace || [],
defaultNS: options['default-ns'] || undefined,
nsSeparator: options['namespace-sep'] || undefined,
nestedSeparator: options['nested-sep'] || undefined,
},
Expand Down

0 comments on commit e268461

Please sign in to comment.