File tree 5 files changed +49
-14
lines changed
5 files changed +49
-14
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ export function createTranslationFiles({
14
14
removeExtraKeys,
15
15
scopes,
16
16
fileFormat,
17
+ scopedOnly,
17
18
} : Config & { scopeToKeys : ScopeMap } ) {
18
19
const logger = getLogger ( ) ;
19
20
@@ -23,21 +24,24 @@ export function createTranslationFiles({
23
24
output,
24
25
fileFormat,
25
26
} ) ;
26
- const globalFiles = langs . map ( ( lang ) => ( {
27
- path : `${ output } /${ lang } .${ fileFormat } ` ,
28
- } ) ) ;
27
+
29
28
const actions : FileAction [ ] = [ ] ;
30
29
31
- for ( const { path } of globalFiles ) {
32
- actions . push (
33
- buildTranslationFile ( {
34
- path,
35
- translation : scopeToKeys . __global ,
36
- replace,
37
- removeExtraKeys,
38
- fileFormat,
39
- } )
40
- ) ;
30
+ if ( ! scopedOnly ) {
31
+ const globalFiles = langs . map ( ( lang ) => ( {
32
+ path : `${ output } /${ lang } .${ fileFormat } ` ,
33
+ } ) ) ;
34
+ for ( const { path } of globalFiles ) {
35
+ actions . push (
36
+ buildTranslationFile ( {
37
+ path,
38
+ translation : scopeToKeys . __global ,
39
+ replace,
40
+ removeExtraKeys,
41
+ fileFormat,
42
+ } )
43
+ ) ;
44
+ }
41
45
}
42
46
43
47
for ( const { path, scope } of scopeFiles ) {
Original file line number Diff line number Diff line change @@ -23,6 +23,19 @@ export function buildTranslationFiles(inlineConfig: Config) {
23
23
const result = buildKeys ( config ) ;
24
24
const { scopeToKeys, fileCount } = result ;
25
25
26
+ if ( config . scopedOnly ) {
27
+ if ( Object . keys ( scopeToKeys . __global ) . length ) {
28
+ logger . log (
29
+ '\n\x1b[31m%s\x1b[0m' ,
30
+ '⚠️' ,
31
+ 'Global keys found with scopedOnly flag active\n'
32
+ ) ;
33
+ if ( config . emitErrorOnExtraKeys ) {
34
+ process . exit ( 2 ) ;
35
+ }
36
+ }
37
+ delete scopeToKeys . __global ;
38
+ }
26
39
logger . success ( `${ messages . extract } 🗝` ) ;
27
40
28
41
let keysFound = 0 ;
Original file line number Diff line number Diff line change @@ -29,6 +29,19 @@ export function findMissingKeys(inlineConfig: Config) {
29
29
30
30
const result = buildKeys ( config ) ;
31
31
logger . success ( `${ messages . extract } 🗝` ) ;
32
+ if ( config . scopedOnly ) {
33
+ if ( Object . keys ( result . scopeToKeys . __global ) . length ) {
34
+ logger . log (
35
+ '\n\x1b[31m%s\x1b[0m' ,
36
+ '⚠️' ,
37
+ 'Global keys found with scopedOnly flag active\n'
38
+ ) ;
39
+ if ( config . emitErrorOnExtraKeys ) {
40
+ process . exit ( 2 ) ;
41
+ }
42
+ }
43
+ delete result . scopeToKeys . __global ;
44
+ }
32
45
33
46
const { addMissingKeys, emitErrorOnExtraKeys } = config ;
34
47
compareKeysToFiles ( {
Original file line number Diff line number Diff line change 1
- export function marker < T extends string | string [ ] > ( key : T ) : T {
1
+ export function marker < T extends string | string [ ] > (
2
+ key : T ,
3
+ params ?: unknown ,
4
+ lang ?: string
5
+ ) : T {
2
6
return key ;
3
7
}
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ export type Config = {
9
9
addMissingKeys ?: boolean ;
10
10
removeExtraKeys ?: boolean ;
11
11
emitErrorOnExtraKeys ?: boolean ;
12
+ scopedOnly ?: boolean ;
12
13
scopes ?: Scopes ;
13
14
scopePathMap ?: {
14
15
[ scopeAlias : string ] : string ;
You can’t perform that action at this time.
0 commit comments