|
1 | 1 | import path from 'path' |
2 | | -import { existsSync, writeFileSync, unlinkSync, readdirSync, rmdirSync } from 'fs' |
3 | | -import { parseAll, hasPhpTranslations, generateFiles } from './loader' |
| 2 | +import { existsSync, unlinkSync, readdirSync, rmdirSync } from 'fs' |
| 3 | +import { hasPhpTranslations, generateFiles, prepareExtendedParsedLangFiles } from './loader' |
4 | 4 | import { ParsedLangFileInterface } from './interfaces/parsed-lang-file' |
| 5 | +import { VitePluginOptionsInterface } from './interfaces/plugin-options' |
5 | 6 | import { Plugin } from 'vite' |
6 | 7 |
|
7 | | -export default function i18n(langPath: string = 'lang'): Plugin { |
| 8 | +export default function i18n(options: string | VitePluginOptionsInterface = 'lang'): Plugin { |
| 9 | + let langPath = typeof options === 'string' ? options : options.langPath ?? 'lang' |
8 | 10 | langPath = langPath.replace(/[\\/]$/, '') + path.sep |
9 | 11 |
|
| 12 | + const additionalLangPaths = typeof options === 'string' ? [] : options.additionalLangPaths ?? [] |
| 13 | + |
10 | 14 | const frameworkLangPath = 'vendor/laravel/framework/src/Illuminate/Translation/lang/'.replace('/', path.sep) |
11 | 15 | let files: ParsedLangFileInterface[] = [] |
12 | 16 | let exitHandlersBound: boolean = false |
@@ -40,11 +44,15 @@ export default function i18n(langPath: string = 'lang'): Plugin { |
40 | 44 | return |
41 | 45 | } |
42 | 46 |
|
43 | | - files = generateFiles(langPath, [...parseAll(frameworkLangPath), ...parseAll(langPath)]) |
| 47 | + const langPaths = prepareExtendedParsedLangFiles([frameworkLangPath, langPath, ...additionalLangPaths]) |
| 48 | + |
| 49 | + files = generateFiles(langPath, langPaths) |
44 | 50 | }, |
45 | 51 | handleHotUpdate(ctx) { |
46 | 52 | if (/lang\/.*\.php$/.test(ctx.file)) { |
47 | | - files = generateFiles(langPath, [...parseAll(frameworkLangPath), ...parseAll(langPath)]) |
| 53 | + const langPaths = prepareExtendedParsedLangFiles([frameworkLangPath, langPath, ...additionalLangPaths]) |
| 54 | + |
| 55 | + files = generateFiles(langPath, langPaths) |
48 | 56 | } |
49 | 57 | }, |
50 | 58 | configureServer(server) { |
|
0 commit comments