generated from hemengke1997/ts-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f656868
commit 01f76b4
Showing
6 changed files
with
50 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,25 @@ | ||
import path from 'node:path' | ||
import { type I18nDetectorOptions } from '..' | ||
|
||
export const DEFAULT_OPTIONS: Required<I18nDetectorOptions> = { | ||
localesPaths: [path.resolve(process.cwd(), './src/locales')], | ||
pathMatcher: '{locale}/{namespaces}.{ext}', | ||
parserPlugins: [], | ||
root: process.cwd(), | ||
} | ||
|
||
export function initOptions(options?: I18nDetectorOptions) { | ||
if (!options) return DEFAULT_OPTIONS | ||
if (options.root) { | ||
if (!options.localesPaths?.length) { | ||
options.localesPaths = DEFAULT_OPTIONS.localesPaths.map((p) => path.resolve(options.root!, p)) | ||
} | ||
} else { | ||
options.root = DEFAULT_OPTIONS.root | ||
} | ||
|
||
return { | ||
...DEFAULT_OPTIONS, | ||
options, | ||
} as Required<I18nDetectorOptions> | ||
} |