1.13.0 • Published 5 months ago

@tonyptang/i18n-helper v1.13.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

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

5 months ago

1.12.0

5 months ago

1.11.0

6 months ago

1.10.2

6 months ago

1.10.1

6 months ago

1.9.0

6 months ago

1.8.0

6 months ago

1.7.0

6 months ago

1.6.0

6 months ago

1.5.0

6 months ago

1.4.0

6 months ago

1.3.0

6 months ago

1.10.0

6 months ago

1.2.0

6 months ago

1.1.1

6 months ago

1.1.0

6 months ago

1.0.0

6 months ago