1.13.0 • Published 9 months ago
@tonyptang/i18n-helper v1.13.0
Run script ih gen to generate language config
// ih.config.ts
import { defineConfig } from '@tonyptang/i18n-helper'
export default defineConfig({
  filename: 'lang.xlsx',
  sheetNames: ['sheet1', 'sheet2'],
  keyColumn: 'B',
  columnToLanguageFile: {
    C: 'cn.json',
    D: 'en.json',
  },
  sheetNameToModule: { // Default is the sheetName
    sheet1: 'common',
    sheet2: 'sheet2'
  },
  savePath: './src/example/langs',
  parseValue(value, key) {
    return JSON.stringify(value)
  },
  checkDuplicateValue: 'C', // check value on column, string | boolean
  checkDuplicateKey: true,
  ignoreRows: [1, 2], // start with 1
})type CheckColumn = string
type IgnoreRowsFn = (moduleName: string) => Promise<number[]> | number[]
export interface UserConfig {
  filename: string
  outputFileType?: 'json' | 'ts' | 'js' | 'yaml'
  sheetNames: string[]
  keyColumn: string
  columnToLanguageFile: Record<string, string>
  ignoreRows?: number[] | IgnoreRowsFn
  sheetNameToModule?: Record<string, string>
  savePath?: string
  parseValue?: (value: string, key: string, moduleName: string) => string
  checkDuplicateValue?: boolean | CheckColumn
  checkDuplicateKey?: boolean
  beforeGenerate?: () => Promise<void> | void
  singleFile?: boolean | string
}
type ConfigFn = () => Promise<UserConfig> | UserConfig
type Config = ConfigFn | UserConfig
type Arrayable<T> = T | T[]
export declare function defineConfig(config: Arrayable<Config>): Promise<Config[]>Run script ih set-config 'filename(en.json)' to set replace target language config
Then run ih 'filename(js|ts|vue)' to replace file content with i18n config
Or run ih 'filename(js|ts|vue)' --i18n-config 'filename(en.json)'
example
// en.json
{
  "testKey": "this is a test",
  "testKey2": {
    "value": "this is a test2"
  }
}// index.vue
<script setup lang="ts">
const message = ref('this is a test')
</script>
<template>
<div>this is a test2</div>
</template>Run ih --i18n-config en.json index.vue
output
// index.vue
<script setup lang="ts">
const message = ref(t('testKey'))
</script>
<template>
<div>{{$t('testKey2.value')}}</div>
</template>1.13.0
9 months ago
1.12.0
9 months ago
1.11.0
10 months ago
1.10.2
10 months ago
1.10.1
10 months ago
1.9.0
10 months ago
1.8.0
10 months ago
1.7.0
10 months ago
1.6.0
10 months ago
1.5.0
10 months ago
1.4.0
10 months ago
1.3.0
10 months ago
1.10.0
10 months ago
1.2.0
10 months ago
1.1.1
10 months ago
1.1.0
10 months ago
1.0.0
10 months ago