Skip to content

Commit

Permalink
fix(break-change): typo
Browse files Browse the repository at this point in the history
  • Loading branch information
hemengke1997 committed Mar 19, 2024
1 parent d270f06 commit aa4ce4d
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 44 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

### Features

* support `autoDetectI18nConfig` option ([9ccaa91](https://github.com/hemengke1997/vite-plugin-i18n-ally/commit/9ccaa9115cf845ec73997d128aaba281baf98632))
* support `useVscodeI18nAllyConfig` option ([9ccaa91](https://github.com/hemengke1997/vite-plugin-i18n-ally/commit/9ccaa9115cf845ec73997d128aaba281baf98632))



Expand Down
20 changes: 10 additions & 10 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,27 @@ pnpm add vite-plugin-i18n-ally -D

**如果已配置i18n.ally,插件会默认读取配置**

| 参数 | 类型 | 默认值 | 描述 |
| -------------------- | --------------------------------------- | ------------------------------------------------------------ | ---------------------------------------------------------------- |
| localesPaths | `string[]` | `i18n-ally.localesPaths \|\| ['./src/locales', './locales']` | 存放语言资源的目录地址,相对于 `root` |
| root | `string` | `process.cwd()` | 项目根路径 |
| namespace | `boolean` | `i18n-ally.namespace \|\| false` | 是否启用命名空间 |
| pathMatcher | `string` | 自动探测 | 资源文件匹配规则 |
| parserPlugins | `ParserPlugin[]` | `[jsonParser, json5Parser, yamlParser]` | 资源文件解析插件 |
| autoDetectI18nConfig | `boolean \| { stopAt: string }` | `true` | 是否自动探测i18n配置项,如果传入stopAt,则会在指定的目录停止探测 |
| 参数 | 类型 | 默认值 | 描述 |
| ----------------------- | --------------------------------------- | ------------------------------------------------------------ | ---------------------------------------------------------------- |
| localesPaths | `string[]` | `i18n-ally.localesPaths \|\| ['./src/locales', './locales']` | 存放语言资源的目录地址,相对于 `root` |
| root | `string` | `process.cwd()` | 项目根路径 |
| namespace | `boolean` | `i18n-ally.namespace \|\| false` | 是否启用命名空间 |
| pathMatcher | `string` | 自动探测 | 资源文件匹配规则 |
| parserPlugins | `ParserPlugin[]` | `[jsonParser, json5Parser, yamlParser]` | 资源文件解析插件 |
| useVscodeI18nAllyConfig | `boolean \| { stopAt: string }` | `true` | 是否自动使用i18n配置项,如果传入stopAt,则会在指定的目录停止探测 |

## 配置参考

### vite.config.ts
```ts
import path from 'node:path'
import { defineConfig } from 'vite'
import { i18nDetector } from 'vite-plugin-i18n-ally'
import { i18n } from 'vite-plugin-i18n-ally'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
i18nDetector({
i18n({
localesPaths: ['./src/locales'],
}),
],
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,27 @@ pnpm add vite-plugin-i18n-ally -D

**If `i18n.ally` is configured, the plugin will read the configuration by default**

| Option | Type | Default | Description |
| -------------------- | --------------------------------------- | ------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------- |
| localesPaths | `string[]` | `i18n-ally.localesPaths \|\| ['./src/locales', './locales']` | The directory of language resources, relative to `root` |
| root | `string` | `process.cwd()` | The project root path |
| namespace | `boolean` | `i18n-ally.namespace \|\| false` | Enable namespace |
| pathMatcher | `string` | auto detected by structure | Resource file matching rule |
| parserPlugins | `ParserPlugin[]` | `[jsonParser, json5Parser, yamlParser]` | Resource file parsing plugin |
| autoDetectI18nConfig | `boolean \| { stopAt: string }` | `true` | Whether to automatically detect i18n-ally configuration, if stopAt is passed in, it will stop detecting in the specified directory |
| Option | Type | Default | Description |
| ----------------------- | --------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------- |
| localesPaths | `string[]` | `i18n-ally.localesPaths \|\| ['./src/locales', './locales']` | The directory of language resources, relative to `root` |
| root | `string` | `process.cwd()` | The project root path |
| namespace | `boolean` | `i18n-ally.namespace \|\| false` | Enable namespace |
| pathMatcher | `string` | auto detected by structure | Resource file matching rule |
| parserPlugins | `ParserPlugin[]` | `[jsonParser, json5Parser, yamlParser]` | Resource file parsing plugin |
| useVscodeI18nAllyConfig | `boolean \| { stopAt: string }` | `true` | Whether to automatically use i18n-ally configuration, if stopAt is passed in, it will stop detecting in the specified directory |

## Config Reference

### vite.config.ts
```ts
import path from 'node:path'
import { defineConfig } from 'vite'
import { i18nDetector } from 'vite-plugin-i18n-ally'
import { i18n } from 'vite-plugin-i18n-ally'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
i18nDetector({
i18n({
localesPaths: ['./src/locales'],
}),
],
Expand Down
6 changes: 3 additions & 3 deletions playground/spa/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
import { i18nDetector } from 'vite-plugin-i18n-ally'
import { i18n } from 'vite-plugin-i18n-ally'

// https://vitejs.dev/config/
export default defineConfig({
base: '/vite-plugin-i18n-ally/',
plugins: [
react(),
i18nDetector({
i18n({
root: __dirname,
localesPaths: ['./src/locales'],
namespace: true,
pathMatcher: '{locale}/{namespace}.{ext}',
autoDetectI18nConfig: false,
useVscodeI18nAllyConfig: false,
}),
],
})
4 changes: 2 additions & 2 deletions playground/vscode-setting/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
import { i18nDetector } from 'vite-plugin-i18n-ally'
import { i18n } from 'vite-plugin-i18n-ally'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
i18nDetector({
i18n({
root: __dirname,
}),
],
Expand Down
12 changes: 6 additions & 6 deletions src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { initOptions } from './utils/init-options'

export type ParserPlugin = ParserConstructor | undefined

export interface I18nDetectorOptions {
export interface I18nAllyOptions {
/**
* @description locales directory paths
*
Expand Down Expand Up @@ -75,20 +75,20 @@ export interface I18nDetectorOptions {
*/
dotVscodePath?: string | false
/**
* @description auto detect config of vscode extension `i18n-ally`
* @description auto use config of vscode extension `i18n-ally`
* @default true
*/
autoDetectI18nConfig?:
useVscodeI18nAllyConfig?:
| boolean
| {
stopAt: string
}
}

export async function i18nDetector(opts?: I18nDetectorOptions): Promise<any> {
export async function i18n(opts?: I18nAllyOptions): Promise<any> {
const options = initOptions(opts)

debug('User input i18nDetector options on init:', options)
debug('User input i18n-ally options on init:', options)

const localeDetector = new LocaleDetector({
root: options.root,
Expand All @@ -101,7 +101,7 @@ export async function i18nDetector(opts?: I18nDetectorOptions): Promise<any> {
await localeDetector.init()

return {
name: 'vite:i18n-detector',
name: 'vite:plugin-i18n-ally',
enforce: 'pre',
config: () => ({
optimizeDeps: {
Expand Down
6 changes: 3 additions & 3 deletions src/plugin/locale-detector/LocaleDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import path from 'node:path'
import trimEnd from 'string.prototype.trimend'
import uniq from 'uniq'
import { normalizePath } from 'vite'
import { type I18nDetectorOptions } from '..'
import { type I18nAllyOptions } from '..'
import { DefaultEnabledParsers } from '../parsers'
import { Parser } from '../parsers/Parser'
import { ParsePathMatcher } from '../path-matcher/PathMatcher'
import { PKGNAME, VIRTUAL } from '../utils/constant'
import { debug } from '../utils/debugger'
import { logger } from '../utils/logger'

export type Config = Omit<Required<I18nDetectorOptions>, 'dotVscodePath' | 'autoDetectI18nConfig'>
export type Config = Omit<Required<I18nAllyOptions>, 'dotVscodePath' | 'useVscodeI18nAllyConfig'>

type PathMatcherType = RegExp

Expand Down Expand Up @@ -84,7 +84,7 @@ export class LocaleDetector {
debug(`🗃 Path Matcher: ${this._pathMatcher.matcher}`)
}

debug(`\n💯 The real i18nDetector options: `, {
debug(`\n💯 The real I18nAlly options: `, {
root: this._rootPath,
localesPaths: this._localesPaths,
pathMatcher: this._pathMatcher.matcher,
Expand Down
17 changes: 9 additions & 8 deletions src/plugin/utils/init-options.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { type I18nDetectorOptions } from '..'
import { type I18nAllyOptions } from '..'
import { I18nAllyVscodeSetting } from './I18nAllyVscodeSetting'
import { debug } from './debugger'

const DEFAULT_OPTIONS: I18nDetectorOptions = {
const DEFAULT_OPTIONS: I18nAllyOptions = {
localesPaths: ['./src/locales', './locales'],
root: process.cwd(),
namespace: false,
autoDetectI18nConfig: true,
useVscodeI18nAllyConfig: true,
}

function getDefaultOptions(options?: I18nDetectorOptions): I18nDetectorOptions {
function getDefaultOptions(options?: I18nAllyOptions): I18nAllyOptions {
if (options?.dotVscodePath !== undefined) {
console.warn(`dotVscodePath is deprecated, please use 'root' instead`)
}

if (options?.autoDetectI18nConfig) {
const stopAt = typeof options.autoDetectI18nConfig === 'object' ? options.autoDetectI18nConfig.stopAt : undefined
if (options?.useVscodeI18nAllyConfig) {
const stopAt =
typeof options.useVscodeI18nAllyConfig === 'object' ? options.useVscodeI18nAllyConfig.stopAt : undefined
const i18nAlly = new I18nAllyVscodeSetting(options?.root || (DEFAULT_OPTIONS.root as string), stopAt).init()

debug('i18n-ally config:', i18nAlly)
Expand All @@ -31,12 +32,12 @@ function getDefaultOptions(options?: I18nDetectorOptions): I18nDetectorOptions {
return DEFAULT_OPTIONS
}

export function initOptions(options?: I18nDetectorOptions) {
export function initOptions(options?: I18nAllyOptions) {
return {
...getDefaultOptions({
...DEFAULT_OPTIONS,
...options,
}),
...options,
} as Required<I18nDetectorOptions>
} as Required<I18nAllyOptions>
}
2 changes: 1 addition & 1 deletion tests/LocaleDetector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('LocaleDetector - Dir mode', () => {
root: path.resolve(__dirname, './fixtures/'),
localesPaths: [path.resolve(__dirname, './fixtures/locales/')],
namespace: true,
autoDetectI18nConfig: false,
useVscodeI18nAllyConfig: false,
})

localeDetector = new LocaleDetector(options)
Expand Down

0 comments on commit aa4ce4d

Please sign in to comment.