@lingui/conf 3.16.1 → 3.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/LICENSE +1 -1
- package/README.md +3 -3
- package/build/LICENSE +1 -1
- package/build/index.d.ts +111 -81
- package/build/index.js +51 -68
- package/index.d.ts +111 -81
- package/package.json +20 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,29 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.17.1](https://github.com/lingui/js-lingui/compare/v3.17.0...v3.17.1) (2023-02-07)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **compile:** remove verbose output when using flow with template ([#1388](https://github.com/lingui/js-lingui/issues/1388)) ([31316f9](https://github.com/lingui/js-lingui/commit/31316f938957dba8e908f9f60a452a2673a934ee))
|
|
12
|
+
* **conf:** lazy load cosmiconfig's TypeScriptLoader ([#1403](https://github.com/lingui/js-lingui/issues/1403)) ([617a333](https://github.com/lingui/js-lingui/commit/617a3330f6eee5ffe5670a6b41f06d0a8116fc92))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# [3.17.0](https://github.com/lingui/js-lingui/compare/v3.16.1...v3.17.0) (2023-02-01)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* **conf:** proper typescript cosmiconfig loader ([#1386](https://github.com/lingui/js-lingui/issues/1386)) ([8da122d](https://github.com/lingui/js-lingui/commit/8da122d7ee65846993a1f3b5f2091d194abef521))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
6
29
|
## [3.16.1](https://github.com/lingui/js-lingui/compare/v3.16.0...v3.16.1) (2023-01-24)
|
|
7
30
|
|
|
8
31
|
**Note:** Version bump only for package @lingui/conf
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2017 Tomáš Ehrlich
|
|
3
|
+
Copyright (c) 2017-2022 Tomáš Ehrlich, (c) 2022-2023 Crowdin.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ const config = getConfig()
|
|
|
23
23
|
// config.localeDir === '/app/locale'
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
See the [reference][reference]
|
|
26
|
+
See the [reference][reference] documentation of `lingui-cli` for all options.
|
|
27
27
|
|
|
28
28
|
## License
|
|
29
29
|
|
|
@@ -31,8 +31,8 @@ This package is licensed under [MIT][license] license.
|
|
|
31
31
|
|
|
32
32
|
[license]: https://github.com/lingui/js-lingui/blob/main/LICENSE
|
|
33
33
|
[linguijs]: https://github.com/lingui/js-lingui
|
|
34
|
-
[documentation]: https://lingui.
|
|
35
|
-
[reference]: https://lingui.
|
|
34
|
+
[documentation]: https://lingui.dev
|
|
35
|
+
[reference]: https://lingui.dev/ref/conf
|
|
36
36
|
[package]: https://www.npmjs.com/package/@lingui/conf
|
|
37
37
|
[badge-downloads]: https://img.shields.io/npm/dw/@lingui/conf.svg
|
|
38
38
|
[badge-version]: https://img.shields.io/npm/v/@lingui/conf.svg
|
package/build/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2017 Tomáš Ehrlich
|
|
3
|
+
Copyright (c) 2017-2022 Tomáš Ehrlich, (c) 2022-2023 Crowdin.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/build/index.d.ts
CHANGED
|
@@ -1,98 +1,124 @@
|
|
|
1
|
-
import type { GeneratorOptions } from "@babel/core"
|
|
1
|
+
import type { GeneratorOptions } from "@babel/core"
|
|
2
2
|
|
|
3
|
-
export declare type CatalogFormat =
|
|
3
|
+
export declare type CatalogFormat =
|
|
4
|
+
| "lingui"
|
|
5
|
+
| "minimal"
|
|
6
|
+
| "po"
|
|
7
|
+
| "csv"
|
|
8
|
+
| "po-gettext"
|
|
4
9
|
export type CatalogFormatOptions = {
|
|
5
|
-
|
|
6
|
-
|
|
10
|
+
origins?: boolean
|
|
11
|
+
lineNumbers?: boolean
|
|
7
12
|
}
|
|
8
|
-
export declare type OrderBy = "messageId" | "origin"
|
|
13
|
+
export declare type OrderBy = "messageId" | "origin"
|
|
9
14
|
declare type CatalogConfig = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
+
name?: string
|
|
16
|
+
path: string
|
|
17
|
+
include: string[]
|
|
18
|
+
exclude?: string[]
|
|
19
|
+
}
|
|
15
20
|
|
|
16
21
|
export type LocaleObject = {
|
|
17
|
-
|
|
22
|
+
[locale: string]: string[] | string
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
export type DefaultLocaleObject = {
|
|
21
|
-
|
|
26
|
+
default: string
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
export declare type FallbackLocales = LocaleObject | DefaultLocaleObject
|
|
25
30
|
|
|
26
31
|
declare type CatalogService = {
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
name: string
|
|
33
|
+
apiKey: string
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
declare type ExtractorType = {
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
match(filename: string): boolean
|
|
38
|
+
extract(filename: string, targetDir: string, options?: any): void
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
export declare type LinguiConfig = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
catalogs: CatalogConfig[]
|
|
43
|
+
compileNamespace: "es" | "cjs" | "ts" | string
|
|
44
|
+
extractBabelOptions: Record<string, unknown>
|
|
45
|
+
compilerBabelOptions: GeneratorOptions
|
|
46
|
+
fallbackLocales: FallbackLocales
|
|
47
|
+
format: CatalogFormat
|
|
48
|
+
extractors?: ExtractorType[]
|
|
49
|
+
prevFormat: CatalogFormat
|
|
50
|
+
formatOptions: CatalogFormatOptions
|
|
51
|
+
localeDir: string
|
|
52
|
+
locales: string[]
|
|
53
|
+
catalogsMergePath: string
|
|
54
|
+
orderBy: OrderBy
|
|
55
|
+
pseudoLocale: string
|
|
56
|
+
rootDir: string
|
|
57
|
+
runtimeConfigModule:
|
|
58
|
+
| [source: string, identifier?: string]
|
|
59
|
+
| {
|
|
53
60
|
i18n?: [source: string, identifier?: string]
|
|
54
61
|
Trans?: [source: string, identifier?: string]
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
export declare const defaultConfig: LinguiConfig
|
|
60
|
-
export declare function getConfig({
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
62
|
+
}
|
|
63
|
+
sourceLocale: string
|
|
64
|
+
service: CatalogService
|
|
65
|
+
}
|
|
66
|
+
export declare const defaultConfig: LinguiConfig
|
|
67
|
+
export declare function getConfig({
|
|
68
|
+
cwd,
|
|
69
|
+
configPath,
|
|
70
|
+
skipValidation,
|
|
71
|
+
}?: {
|
|
72
|
+
cwd?: string
|
|
73
|
+
configPath?: string
|
|
74
|
+
skipValidation?: boolean
|
|
75
|
+
}): LinguiConfig
|
|
76
|
+
|
|
77
|
+
export declare function makeConfig(
|
|
78
|
+
userConfig: Partial<LinguiConfig>,
|
|
79
|
+
opts?: {
|
|
80
|
+
skipValidation?: boolean
|
|
81
|
+
}
|
|
82
|
+
): LinguiConfig
|
|
83
|
+
|
|
65
84
|
export declare const configValidation: {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
85
|
+
exampleConfig: {
|
|
86
|
+
extractBabelOptions: {
|
|
87
|
+
extends: string
|
|
88
|
+
rootMode: string
|
|
89
|
+
plugins: string[]
|
|
90
|
+
presets: string[]
|
|
91
|
+
}
|
|
92
|
+
compilerBabelOptions: GeneratorOptions
|
|
93
|
+
catalogs: CatalogConfig[]
|
|
94
|
+
compileNamespace: "es" | "ts" | "cjs" | string
|
|
95
|
+
fallbackLocales: FallbackLocales
|
|
96
|
+
format: CatalogFormat
|
|
97
|
+
formatOptions: CatalogFormatOptions
|
|
98
|
+
locales: string[]
|
|
99
|
+
orderBy: OrderBy
|
|
100
|
+
pseudoLocale: string
|
|
101
|
+
rootDir: string
|
|
102
|
+
runtimeConfigModule: LinguiConfig["runtimeConfigModule"]
|
|
103
|
+
sourceLocale: string
|
|
104
|
+
service: CatalogService
|
|
105
|
+
}
|
|
106
|
+
deprecatedConfig: {
|
|
107
|
+
fallbackLocale: (
|
|
108
|
+
config: LinguiConfig & DeprecatedFallbackLanguage
|
|
109
|
+
) => string
|
|
110
|
+
localeDir: (config: LinguiConfig & DeprecatedLocaleDir) => string
|
|
111
|
+
srcPathDirs: (config: LinguiConfig & DeprecatedLocaleDir) => string
|
|
112
|
+
srcPathIgnorePatterns: (
|
|
113
|
+
config: LinguiConfig & DeprecatedLocaleDir
|
|
114
|
+
) => string
|
|
115
|
+
}
|
|
116
|
+
comment: string
|
|
117
|
+
}
|
|
118
|
+
export declare function replaceRootDir(
|
|
119
|
+
config: LinguiConfig,
|
|
120
|
+
rootDir: string
|
|
121
|
+
): LinguiConfig
|
|
96
122
|
/**
|
|
97
123
|
* Replace fallbackLocale with fallbackLocales
|
|
98
124
|
*
|
|
@@ -100,10 +126,12 @@ export declare function replaceRootDir(config: LinguiConfig, rootDir: string): L
|
|
|
100
126
|
* Remove anytime after 4.x
|
|
101
127
|
*/
|
|
102
128
|
declare type DeprecatedFallbackLanguage = {
|
|
103
|
-
|
|
104
|
-
}
|
|
129
|
+
fallbackLocale: string | null
|
|
130
|
+
}
|
|
105
131
|
|
|
106
|
-
export declare function fallbackLanguageMigration(
|
|
132
|
+
export declare function fallbackLanguageMigration(
|
|
133
|
+
config: LinguiConfig & DeprecatedFallbackLanguage
|
|
134
|
+
): LinguiConfig
|
|
107
135
|
/**
|
|
108
136
|
* Replace localeDir, srcPathDirs and srcPathIgnorePatterns with catalogs
|
|
109
137
|
*
|
|
@@ -111,10 +139,12 @@ export declare function fallbackLanguageMigration(config: LinguiConfig & Depreca
|
|
|
111
139
|
* Remove anytime after 4.x
|
|
112
140
|
*/
|
|
113
141
|
declare type DeprecatedLocaleDir = {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
export declare function catalogMigration(
|
|
119
|
-
|
|
142
|
+
localeDir: string
|
|
143
|
+
srcPathDirs: string[]
|
|
144
|
+
srcPathIgnorePatterns: string[]
|
|
145
|
+
}
|
|
146
|
+
export declare function catalogMigration(
|
|
147
|
+
config: LinguiConfig & DeprecatedLocaleDir
|
|
148
|
+
): LinguiConfig
|
|
149
|
+
export {}
|
|
120
150
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.js
CHANGED
|
@@ -3,29 +3,24 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.catalogMigration = catalogMigration;
|
|
7
|
+
exports.defaultConfig = exports.configValidation = void 0;
|
|
8
|
+
exports.fallbackLanguageMigration = fallbackLanguageMigration;
|
|
6
9
|
exports.getConfig = getConfig;
|
|
10
|
+
exports.makeConfig = makeConfig;
|
|
7
11
|
exports.replaceRootDir = replaceRootDir;
|
|
8
|
-
exports.fallbackLanguageMigration = fallbackLanguageMigration;
|
|
9
|
-
exports.catalogMigration = catalogMigration;
|
|
10
|
-
exports.configValidation = exports.defaultConfig = void 0;
|
|
11
|
-
|
|
12
12
|
var _path = _interopRequireDefault(require("path"));
|
|
13
|
-
|
|
14
13
|
var _fs = _interopRequireDefault(require("fs"));
|
|
15
|
-
|
|
16
14
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
17
|
-
|
|
18
15
|
var _cosmiconfig = require("cosmiconfig");
|
|
19
|
-
|
|
20
16
|
var _jestValidate = require("jest-validate");
|
|
21
|
-
|
|
22
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
18
|
// Enforce posix path delimiters internally
|
|
25
|
-
const pathJoinPosix = (...values) => _path.default
|
|
26
|
-
|
|
19
|
+
const pathJoinPosix = (...values) => _path.default
|
|
20
|
+
// normalize double slashes
|
|
21
|
+
.join(...values)
|
|
22
|
+
// convert platform specific path.sep to posix
|
|
27
23
|
.split(_path.default.sep).join("/");
|
|
28
|
-
|
|
29
24
|
const defaultConfig = {
|
|
30
25
|
catalogs: [{
|
|
31
26
|
path: pathJoinPosix("<rootDir>", "locale", "{locale}", "messages"),
|
|
@@ -62,11 +57,21 @@ const defaultConfig = {
|
|
|
62
57
|
}
|
|
63
58
|
};
|
|
64
59
|
exports.defaultConfig = defaultConfig;
|
|
65
|
-
|
|
66
60
|
function configExists(path) {
|
|
67
61
|
return path && _fs.default.existsSync(path);
|
|
68
62
|
}
|
|
69
|
-
|
|
63
|
+
function TypeScriptLoader() {
|
|
64
|
+
let loaderInstance;
|
|
65
|
+
return (filepath, content) => {
|
|
66
|
+
if (!loaderInstance) {
|
|
67
|
+
const {
|
|
68
|
+
TypeScriptLoader
|
|
69
|
+
} = require("cosmiconfig-typescript-loader");
|
|
70
|
+
loaderInstance = TypeScriptLoader();
|
|
71
|
+
}
|
|
72
|
+
return loaderInstance(filepath, content);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
70
75
|
function getConfig({
|
|
71
76
|
cwd,
|
|
72
77
|
configPath,
|
|
@@ -77,28 +82,38 @@ function getConfig({
|
|
|
77
82
|
const configExplorer = (0, _cosmiconfig.cosmiconfigSync)(moduleName, {
|
|
78
83
|
searchPlaces: ["package.json", `.${moduleName}rc`, `.${moduleName}rc.json`, `.${moduleName}rc.yaml`, `.${moduleName}rc.yml`, `.${moduleName}rc.ts`, `.${moduleName}rc.js`, `${moduleName}.config.ts`, `${moduleName}.config.js`],
|
|
79
84
|
loaders: {
|
|
80
|
-
".ts": TypeScriptLoader
|
|
85
|
+
".ts": TypeScriptLoader()
|
|
81
86
|
}
|
|
82
87
|
});
|
|
83
88
|
const result = configExists(configPath) ? configExplorer.load(configPath) : configExplorer.search(defaultRootDir);
|
|
84
89
|
const userConfig = result ? result.config : {};
|
|
85
|
-
|
|
90
|
+
return makeConfig({
|
|
86
91
|
rootDir: result ? _path.default.dirname(result.filepath) : defaultRootDir,
|
|
87
92
|
...userConfig
|
|
93
|
+
}, {
|
|
94
|
+
skipValidation
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function makeConfig(userConfig, opts = {}) {
|
|
98
|
+
const config = {
|
|
99
|
+
...defaultConfig,
|
|
100
|
+
...userConfig
|
|
88
101
|
};
|
|
89
|
-
|
|
90
|
-
if (!skipValidation) {
|
|
102
|
+
if (!opts.skipValidation) {
|
|
91
103
|
(0, _jestValidate.validate)(config, configValidation);
|
|
92
|
-
return pipe(
|
|
93
|
-
|
|
94
|
-
|
|
104
|
+
return pipe(
|
|
105
|
+
// List config migrations from oldest to newest
|
|
106
|
+
fallbackLanguageMigration, catalogMigration,
|
|
107
|
+
// Custom validation
|
|
108
|
+
validateLocales,
|
|
109
|
+
// `replaceRootDir` should always be the last
|
|
95
110
|
config => replaceRootDir(config, config.rootDir))(config);
|
|
96
111
|
} else {
|
|
97
112
|
return replaceRootDir(config, config.rootDir);
|
|
98
113
|
}
|
|
99
114
|
}
|
|
100
|
-
|
|
101
|
-
|
|
115
|
+
const exampleConfig = {
|
|
116
|
+
...defaultConfig,
|
|
102
117
|
extractors: (0, _jestValidate.multipleValidOptions)([], ["babel"], [{
|
|
103
118
|
match: fileName => false,
|
|
104
119
|
extract: (filename, targetDir, options) => {}
|
|
@@ -119,10 +134,10 @@ const exampleConfig = { ...defaultConfig,
|
|
|
119
134
|
rootMode: "rootmode",
|
|
120
135
|
plugins: ["plugin"],
|
|
121
136
|
presets: ["preset"],
|
|
122
|
-
targets: (0, _jestValidate.multipleValidOptions)({},
|
|
137
|
+
targets: (0, _jestValidate.multipleValidOptions)({}, "> 0.5%", ["> 0.5%", "not dead"], undefined),
|
|
123
138
|
assumptions: (0, _jestValidate.multipleValidOptions)({}, undefined),
|
|
124
139
|
browserslistConfigFile: (0, _jestValidate.multipleValidOptions)(true, undefined),
|
|
125
|
-
browserslistEnv: (0, _jestValidate.multipleValidOptions)(
|
|
140
|
+
browserslistEnv: (0, _jestValidate.multipleValidOptions)(".browserslistrc", undefined)
|
|
126
141
|
}
|
|
127
142
|
};
|
|
128
143
|
const deprecatedConfig = {
|
|
@@ -173,23 +188,19 @@ const deprecatedConfig = {
|
|
|
173
188
|
const configValidation = {
|
|
174
189
|
exampleConfig,
|
|
175
190
|
deprecatedConfig,
|
|
176
|
-
comment: "Documentation: https://lingui.
|
|
191
|
+
comment: "Documentation: https://lingui.dev/ref/conf"
|
|
177
192
|
};
|
|
178
193
|
exports.configValidation = configValidation;
|
|
179
|
-
|
|
180
194
|
function validateLocales(config) {
|
|
181
195
|
if (!Array.isArray(config.locales) || !config.locales.length) {
|
|
182
196
|
console.error("No locales defined!\n");
|
|
183
|
-
console.error(`Add ${_chalk.default.yellow("'locales'")} to your configuration. See ${_chalk.default.underline("https://lingui.
|
|
197
|
+
console.error(`Add ${_chalk.default.yellow("'locales'")} to your configuration. See ${_chalk.default.underline("https://lingui.dev/ref/conf#locales")}`);
|
|
184
198
|
}
|
|
185
|
-
|
|
186
199
|
return config;
|
|
187
200
|
}
|
|
188
|
-
|
|
189
201
|
function replaceRootDir(config, rootDir) {
|
|
190
202
|
return function replaceDeep(value, rootDir) {
|
|
191
203
|
const replace = s => s.replace("<rootDir>", rootDir);
|
|
192
|
-
|
|
193
204
|
if (value == null) {
|
|
194
205
|
return value;
|
|
195
206
|
} else if (typeof value === "string") {
|
|
@@ -203,47 +214,43 @@ function replaceRootDir(config, rootDir) {
|
|
|
203
214
|
if (key !== newKey) delete value[key];
|
|
204
215
|
});
|
|
205
216
|
}
|
|
206
|
-
|
|
207
217
|
return value;
|
|
208
218
|
}(config, rootDir);
|
|
209
219
|
}
|
|
220
|
+
|
|
210
221
|
/**
|
|
211
222
|
* Replace fallbackLocale, by the new standard fallbackLocales
|
|
212
223
|
* - https://github.com/lingui/js-lingui/issues/791
|
|
213
224
|
* - Remove anytime after 4.x
|
|
214
225
|
*/
|
|
215
226
|
|
|
216
|
-
|
|
217
227
|
function fallbackLanguageMigration(config) {
|
|
218
228
|
const {
|
|
219
229
|
fallbackLocale,
|
|
220
230
|
fallbackLocales
|
|
221
231
|
} = config;
|
|
222
|
-
if (fallbackLocales === false) return {
|
|
232
|
+
if (fallbackLocales === false) return {
|
|
233
|
+
...config,
|
|
223
234
|
fallbackLocales: null
|
|
224
235
|
};
|
|
225
|
-
const DEFAULT_FALLBACK = fallbackLocales
|
|
226
|
-
|
|
236
|
+
const DEFAULT_FALLBACK = (fallbackLocales === null || fallbackLocales === void 0 ? void 0 : fallbackLocales.default) || fallbackLocale;
|
|
227
237
|
if (DEFAULT_FALLBACK) {
|
|
228
238
|
if (!config.fallbackLocales) config.fallbackLocales = {};
|
|
229
239
|
config.fallbackLocales.default = DEFAULT_FALLBACK;
|
|
230
240
|
}
|
|
231
|
-
|
|
232
241
|
if (config.fallbackLocales !== false && !config.fallbackLocales.default) {
|
|
233
242
|
config.locales.forEach(locale => {
|
|
234
243
|
const fl = getCldrParentLocale(locale.toLowerCase());
|
|
235
|
-
|
|
236
244
|
if (fl && !config.fallbackLocales[locale]) {
|
|
237
|
-
config.fallbackLocales = {
|
|
245
|
+
config.fallbackLocales = {
|
|
246
|
+
...config.fallbackLocales,
|
|
238
247
|
[locale]: fl
|
|
239
248
|
};
|
|
240
249
|
}
|
|
241
250
|
});
|
|
242
251
|
}
|
|
243
|
-
|
|
244
252
|
return config;
|
|
245
253
|
}
|
|
246
|
-
|
|
247
254
|
function getCldrParentLocale(sourceLocale) {
|
|
248
255
|
return {
|
|
249
256
|
"en-ag": "en",
|
|
@@ -422,6 +429,7 @@ function getCldrParentLocale(sourceLocale) {
|
|
|
422
429
|
"zh-hant-mo": "zh-hant-hk"
|
|
423
430
|
}[sourceLocale];
|
|
424
431
|
}
|
|
432
|
+
|
|
425
433
|
/**
|
|
426
434
|
* Replace localeDir, srcPathDirs and srcPathIgnorePatterns with catalogs
|
|
427
435
|
*
|
|
@@ -429,7 +437,6 @@ function getCldrParentLocale(sourceLocale) {
|
|
|
429
437
|
* Remove anytime after 4.x
|
|
430
438
|
*/
|
|
431
439
|
|
|
432
|
-
|
|
433
440
|
function catalogMigration(config) {
|
|
434
441
|
let {
|
|
435
442
|
localeDir,
|
|
@@ -437,48 +444,24 @@ function catalogMigration(config) {
|
|
|
437
444
|
srcPathIgnorePatterns,
|
|
438
445
|
...newConfig
|
|
439
446
|
} = config;
|
|
440
|
-
|
|
441
447
|
if (localeDir || srcPathDirs || srcPathIgnorePatterns) {
|
|
442
448
|
// Replace missing values with default ones
|
|
443
449
|
if (localeDir === undefined) localeDir = pathJoinPosix("<rootDir>", "locale", "{locale}", "messages");
|
|
444
450
|
if (srcPathDirs === undefined) srcPathDirs = ["<rootDir>"];
|
|
445
451
|
if (srcPathIgnorePatterns === undefined) srcPathIgnorePatterns = ["**/node_modules/**"];
|
|
446
452
|
let newLocaleDir = localeDir.split(_path.default.sep).join("/");
|
|
447
|
-
|
|
448
453
|
if (newLocaleDir.slice(-1) !== _path.default.sep) {
|
|
449
454
|
newLocaleDir += "/";
|
|
450
455
|
}
|
|
451
|
-
|
|
452
456
|
if (!Array.isArray(newConfig.catalogs)) {
|
|
453
457
|
newConfig.catalogs = [];
|
|
454
458
|
}
|
|
455
|
-
|
|
456
459
|
newConfig.catalogs.push({
|
|
457
460
|
path: pathJoinPosix(newLocaleDir, "{locale}", "messages"),
|
|
458
461
|
include: srcPathDirs,
|
|
459
462
|
exclude: srcPathIgnorePatterns
|
|
460
463
|
});
|
|
461
464
|
}
|
|
462
|
-
|
|
463
465
|
return newConfig;
|
|
464
466
|
}
|
|
465
|
-
|
|
466
|
-
const pipe = (...functions) => args => functions.reduce((arg, fn) => fn(arg), args);
|
|
467
|
-
/** Typescript loader using just typescript API and eval(), instead of using ts-node/register which is slower */
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
function TypeScriptLoader(filePath) {
|
|
471
|
-
const tsc = require("typescript");
|
|
472
|
-
|
|
473
|
-
const fileContent = _fs.default.readFileSync(filePath, "utf-8");
|
|
474
|
-
|
|
475
|
-
const {
|
|
476
|
-
outputText
|
|
477
|
-
} = tsc.transpileModule(fileContent, {
|
|
478
|
-
compilerOptions: {
|
|
479
|
-
module: tsc.ModuleKind.CommonJS
|
|
480
|
-
}
|
|
481
|
-
});
|
|
482
|
-
const configFileParsed = eval(outputText);
|
|
483
|
-
return configFileParsed;
|
|
484
|
-
}
|
|
467
|
+
const pipe = (...functions) => args => functions.reduce((arg, fn) => fn(arg), args);
|
package/index.d.ts
CHANGED
|
@@ -1,98 +1,124 @@
|
|
|
1
|
-
import type { GeneratorOptions } from "@babel/core"
|
|
1
|
+
import type { GeneratorOptions } from "@babel/core"
|
|
2
2
|
|
|
3
|
-
export declare type CatalogFormat =
|
|
3
|
+
export declare type CatalogFormat =
|
|
4
|
+
| "lingui"
|
|
5
|
+
| "minimal"
|
|
6
|
+
| "po"
|
|
7
|
+
| "csv"
|
|
8
|
+
| "po-gettext"
|
|
4
9
|
export type CatalogFormatOptions = {
|
|
5
|
-
|
|
6
|
-
|
|
10
|
+
origins?: boolean
|
|
11
|
+
lineNumbers?: boolean
|
|
7
12
|
}
|
|
8
|
-
export declare type OrderBy = "messageId" | "origin"
|
|
13
|
+
export declare type OrderBy = "messageId" | "origin"
|
|
9
14
|
declare type CatalogConfig = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
+
name?: string
|
|
16
|
+
path: string
|
|
17
|
+
include: string[]
|
|
18
|
+
exclude?: string[]
|
|
19
|
+
}
|
|
15
20
|
|
|
16
21
|
export type LocaleObject = {
|
|
17
|
-
|
|
22
|
+
[locale: string]: string[] | string
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
export type DefaultLocaleObject = {
|
|
21
|
-
|
|
26
|
+
default: string
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
export declare type FallbackLocales = LocaleObject | DefaultLocaleObject
|
|
25
30
|
|
|
26
31
|
declare type CatalogService = {
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
name: string
|
|
33
|
+
apiKey: string
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
declare type ExtractorType = {
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
match(filename: string): boolean
|
|
38
|
+
extract(filename: string, targetDir: string, options?: any): void
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
export declare type LinguiConfig = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
catalogs: CatalogConfig[]
|
|
43
|
+
compileNamespace: "es" | "cjs" | "ts" | string
|
|
44
|
+
extractBabelOptions: Record<string, unknown>
|
|
45
|
+
compilerBabelOptions: GeneratorOptions
|
|
46
|
+
fallbackLocales: FallbackLocales
|
|
47
|
+
format: CatalogFormat
|
|
48
|
+
extractors?: ExtractorType[]
|
|
49
|
+
prevFormat: CatalogFormat
|
|
50
|
+
formatOptions: CatalogFormatOptions
|
|
51
|
+
localeDir: string
|
|
52
|
+
locales: string[]
|
|
53
|
+
catalogsMergePath: string
|
|
54
|
+
orderBy: OrderBy
|
|
55
|
+
pseudoLocale: string
|
|
56
|
+
rootDir: string
|
|
57
|
+
runtimeConfigModule:
|
|
58
|
+
| [source: string, identifier?: string]
|
|
59
|
+
| {
|
|
53
60
|
i18n?: [source: string, identifier?: string]
|
|
54
61
|
Trans?: [source: string, identifier?: string]
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
export declare const defaultConfig: LinguiConfig
|
|
60
|
-
export declare function getConfig({
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
62
|
+
}
|
|
63
|
+
sourceLocale: string
|
|
64
|
+
service: CatalogService
|
|
65
|
+
}
|
|
66
|
+
export declare const defaultConfig: LinguiConfig
|
|
67
|
+
export declare function getConfig({
|
|
68
|
+
cwd,
|
|
69
|
+
configPath,
|
|
70
|
+
skipValidation,
|
|
71
|
+
}?: {
|
|
72
|
+
cwd?: string
|
|
73
|
+
configPath?: string
|
|
74
|
+
skipValidation?: boolean
|
|
75
|
+
}): LinguiConfig
|
|
76
|
+
|
|
77
|
+
export declare function makeConfig(
|
|
78
|
+
userConfig: Partial<LinguiConfig>,
|
|
79
|
+
opts?: {
|
|
80
|
+
skipValidation?: boolean
|
|
81
|
+
}
|
|
82
|
+
): LinguiConfig
|
|
83
|
+
|
|
65
84
|
export declare const configValidation: {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
85
|
+
exampleConfig: {
|
|
86
|
+
extractBabelOptions: {
|
|
87
|
+
extends: string
|
|
88
|
+
rootMode: string
|
|
89
|
+
plugins: string[]
|
|
90
|
+
presets: string[]
|
|
91
|
+
}
|
|
92
|
+
compilerBabelOptions: GeneratorOptions
|
|
93
|
+
catalogs: CatalogConfig[]
|
|
94
|
+
compileNamespace: "es" | "ts" | "cjs" | string
|
|
95
|
+
fallbackLocales: FallbackLocales
|
|
96
|
+
format: CatalogFormat
|
|
97
|
+
formatOptions: CatalogFormatOptions
|
|
98
|
+
locales: string[]
|
|
99
|
+
orderBy: OrderBy
|
|
100
|
+
pseudoLocale: string
|
|
101
|
+
rootDir: string
|
|
102
|
+
runtimeConfigModule: LinguiConfig["runtimeConfigModule"]
|
|
103
|
+
sourceLocale: string
|
|
104
|
+
service: CatalogService
|
|
105
|
+
}
|
|
106
|
+
deprecatedConfig: {
|
|
107
|
+
fallbackLocale: (
|
|
108
|
+
config: LinguiConfig & DeprecatedFallbackLanguage
|
|
109
|
+
) => string
|
|
110
|
+
localeDir: (config: LinguiConfig & DeprecatedLocaleDir) => string
|
|
111
|
+
srcPathDirs: (config: LinguiConfig & DeprecatedLocaleDir) => string
|
|
112
|
+
srcPathIgnorePatterns: (
|
|
113
|
+
config: LinguiConfig & DeprecatedLocaleDir
|
|
114
|
+
) => string
|
|
115
|
+
}
|
|
116
|
+
comment: string
|
|
117
|
+
}
|
|
118
|
+
export declare function replaceRootDir(
|
|
119
|
+
config: LinguiConfig,
|
|
120
|
+
rootDir: string
|
|
121
|
+
): LinguiConfig
|
|
96
122
|
/**
|
|
97
123
|
* Replace fallbackLocale with fallbackLocales
|
|
98
124
|
*
|
|
@@ -100,10 +126,12 @@ export declare function replaceRootDir(config: LinguiConfig, rootDir: string): L
|
|
|
100
126
|
* Remove anytime after 4.x
|
|
101
127
|
*/
|
|
102
128
|
declare type DeprecatedFallbackLanguage = {
|
|
103
|
-
|
|
104
|
-
}
|
|
129
|
+
fallbackLocale: string | null
|
|
130
|
+
}
|
|
105
131
|
|
|
106
|
-
export declare function fallbackLanguageMigration(
|
|
132
|
+
export declare function fallbackLanguageMigration(
|
|
133
|
+
config: LinguiConfig & DeprecatedFallbackLanguage
|
|
134
|
+
): LinguiConfig
|
|
107
135
|
/**
|
|
108
136
|
* Replace localeDir, srcPathDirs and srcPathIgnorePatterns with catalogs
|
|
109
137
|
*
|
|
@@ -111,10 +139,12 @@ export declare function fallbackLanguageMigration(config: LinguiConfig & Depreca
|
|
|
111
139
|
* Remove anytime after 4.x
|
|
112
140
|
*/
|
|
113
141
|
declare type DeprecatedLocaleDir = {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
export declare function catalogMigration(
|
|
119
|
-
|
|
142
|
+
localeDir: string
|
|
143
|
+
srcPathDirs: string[]
|
|
144
|
+
srcPathIgnorePatterns: string[]
|
|
145
|
+
}
|
|
146
|
+
export declare function catalogMigration(
|
|
147
|
+
config: LinguiConfig & DeprecatedLocaleDir
|
|
148
|
+
): LinguiConfig
|
|
149
|
+
export {}
|
|
120
150
|
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/conf",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.17.1",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"description": "Get lingui configuration from package.json",
|
|
6
6
|
"keywords": [
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"node": ">=14.0.0"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@babel/runtime": "^7.
|
|
22
|
+
"@babel/runtime": "^7.20.13",
|
|
23
23
|
"chalk": "^4.1.0",
|
|
24
|
-
"cosmiconfig": "^
|
|
25
|
-
"cosmiconfig-typescript-loader": "^
|
|
24
|
+
"cosmiconfig": "^8.0.0",
|
|
25
|
+
"cosmiconfig-typescript-loader": "^4.3.0",
|
|
26
26
|
"jest-validate": "^26.5.2",
|
|
27
27
|
"lodash.get": "^4.4.2"
|
|
28
28
|
},
|
|
@@ -32,5 +32,20 @@
|
|
|
32
32
|
"index.js",
|
|
33
33
|
"index.d.ts"
|
|
34
34
|
],
|
|
35
|
-
"
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"ts-node": "^10.9.1"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"ts-node": ">=10",
|
|
40
|
+
"typescript": ">=4"
|
|
41
|
+
},
|
|
42
|
+
"peerDependenciesMeta": {
|
|
43
|
+
"ts-node": {
|
|
44
|
+
"optional": true
|
|
45
|
+
},
|
|
46
|
+
"typescript": {
|
|
47
|
+
"optional": true
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"gitHead": "76ef4e8d1c668578ce2c3829ebf35d22ca5e679c"
|
|
36
51
|
}
|