Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
Voerka I18n
https://github.com/zhangfisher/voerka-i18n
Admin
Nodejs/Vue/React International solutions
Tokens:
54,678
Snippets:
392
Trust Score:
8.3
License:
MIT
Update:
1 year ago
Context
Chat
Benchmark
76
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
### Installing VoerkaI18n CLI Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/intro/get-started.md Provides commands to install the VoerkaI18n command-line interface globally using npm, yarn, or pnpm. This tool is essential for project initialization and content extraction. ```shell > npm install -g @voerkai18n/cli > yarn global add @voerkai18n/cli > pnpm add -g @voerkai18n/cli ``` -------------------------------- ### Develop SolidStart Project with npm run dev Source: https://github.com/zhangfisher/voerka-i18n/blob/master/examples/solid/README.md Commands to start the development server for a SolidStart project. After installing dependencies, these commands launch the server, with an option to open the application in a browser. Requires Node.js and npm. ```bash npm run dev # or start the server and open the app in a new browser tab npm run dev -- --open ``` -------------------------------- ### Start Next.js Development Server Source: https://github.com/zhangfisher/voerka-i18n/blob/master/examples/nextjs/README.md Commands to initiate the development server for the Next.js project using different package managers. This allows for local development and testing of the application. ```bash npm run dev # or yarn dev # or pnpm dev # or bun dev ``` -------------------------------- ### Loading Language Packs from Server Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/intro/get-started.md Provides an example of a language pack loader function that fetches JSON language files from a server. This function is crucial for enabling dynamic language pack patches and adding support for new languages without modifying the application code. ```javascript module.exports = async (language,scope)=>{ return await (await fetch(`/languages/${scope.id}/${language}.json`)).json() } ``` -------------------------------- ### Initializing VoerkaI18n Project Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/intro/get-started.md Illustrates the command to initialize a new multilingual environment for a project using the `voerkai18n init` command. This command sets up the necessary directory structure and configuration files. ```shell > voerkai18n init ``` -------------------------------- ### Create SolidStart Project using npm init Source: https://github.com/zhangfisher/voerka-i18n/blob/master/examples/solid/README.md Commands to create a new SolidStart project. This initializes a project in the current directory or a specified directory name. It requires npm to be installed. ```bash # create a new project in the current directory npm init solid@latest # create a new project in my-app npm init solid@latest my-app ``` -------------------------------- ### Install VoerkaI18n CLI Tool Globally Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/intro/install.md Installs the VoerkaI18n command-line interface globally using various package managers. This CLI tool is essential for text extraction and compilation. ```bash npm install -g @voerkai18n/cli ``` ```bash yarn global add @voerkai18n/cli ``` ```bash pnpm add -g @voerkai18n/cli ``` -------------------------------- ### Astro Project Commands with pnpm Source: https://github.com/zhangfisher/voerka-i18n/blob/master/examples/astro/README.md This table lists essential commands for managing an Astro project using pnpm. It covers dependency installation, starting the development server, building for production, previewing the build, and running Astro CLI commands. ```text | Command | Action | | :------------------------ | :----------------------------------------------- | | `pnpm install` | Installs dependencies | | `pnpm dev` | Starts local dev server at `localhost:4321` | | `pnpm build` | Build your production site to `./dist/` | | `pnpm preview` | Preview your build locally, before deploying | | `pnpm astro ...` | Run CLI commands like `astro add`, `astro check` | | `pnpm astro -- --help` | Get help using the Astro CLI | ``` -------------------------------- ### Install VoerkaI18n CLI Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/index.md Installs the VoerkaI18n command-line interface globally using npm, yarn, or pnpm. This CLI tool is essential for managing internationalization tasks within your project. ```shell npm install @voerkai18n/cli -g yarn global add @voerkai18n/cli pnpm add -g @voerkai18n/cli ``` -------------------------------- ### Install unplugin-starter Package Source: https://github.com/zhangfisher/voerka-i18n/blob/master/packages/plugins/README.md Installs the 'unplugin-starter' package as a project dependency. This is the first step before integrating it with build tools. ```bash npm i unplugin-starter ``` -------------------------------- ### Markdown Image Syntax Example Source: https://github.com/zhangfisher/voerka-i18n/blob/master/examples/astro/src/content/blog/markdown-style-guide.md Demonstrates the correct Markdown syntax for including images. It shows how to specify the alt text and the relative or absolute path to the image file. This is crucial for web accessibility and SEO. ```markdown  ``` -------------------------------- ### Installation Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/zh/guide/tools/cli.md Instructions on how to globally install the @voerkai18n/cli package using npm, yarn, or pnpm. ```APIDOC ## Installation Globally install the `@voerkai18n/cli` tool. ```bash > npm install -g @voerkai18n/cli ``` ```bash > yarn global add @voerkai18n/cli ``` ```bash > pnpm add -g @voerkai18n/cli ``` ``` -------------------------------- ### Markdown Ordered List Syntax Example Source: https://github.com/zhangfisher/voerka-i18n/blob/master/examples/astro/src/content/blog/markdown-style-guide.md Provides the syntax for creating ordered lists in Markdown. Each list item is preceded by a number followed by a period. This is used for sequential or numbered items. ```markdown 1. First item 2. Second item 3. Third item ``` -------------------------------- ### Install @voerkai18n/runtime and @voerkai18n/lit Source: https://github.com/zhangfisher/voerka-i18n/blob/master/packages/lit/README.md Installs the necessary runtime and Lit integration packages for VoerkaI18n using npm. Also installs the global CLI tool. ```bash npm install @voerkai18n/runtime @voerkai18n/lit npm install -g @voerkai18n/cli ``` -------------------------------- ### Automatic Translation Commands Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/intro/get-started.md These commands initiate automatic translation using VoerkaI18n. They support different translation providers like Baidu Translation and AI translation services compatible with OpenAI API. You need to provide relevant API keys and URLs. ```bash >voerkai18n translate --api-key <key applied from Baidu Translation> --api-id <appid applied from Baidu Translation> --provider baidu ``` ```bash >voerkai18n translate --api-key <API key> --api-url <AI API URL> --api-model <model name> ``` -------------------------------- ### Switching Languages with VoerkaI18n Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/intro/get-started.md Demonstrates how to change the application's current language using the `change` method. This can be done via the `i18nScope` or the global `VoerkaI18n` singleton. The operation is asynchronous and requires awaiting its completion. ```javascript import { i18nScope } from "./languages" // Switch to English await i18nScope.change("en") // Or VoerkaI18n is a global singleton, can be accessed directly await VoerkaI18n.change("en") ``` -------------------------------- ### Markdown Table Syntax Example Source: https://github.com/zhangfisher/voerka-i18n/blob/master/examples/astro/src/content/blog/markdown-style-guide.md Shows the Markdown syntax for creating tables. Tables are defined using pipes '|' to separate columns and hyphens '-' to create header separators. This enables structured data presentation within Markdown documents. ```markdown | Italics | Bold | Code | | --------- | -------- | ------ | | _italics_ | **bold** | `code` | ``` -------------------------------- ### Extracting Translatable Text with VoerkaI18n CLI Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/intro/get-started.md Shows the command used to automatically scan project source files and extract all text content wrapped in the `t` function. The extracted text is saved into `myapp/languages/translates/messages/default.json`. ```shell myapp>voerkai18n extract ``` -------------------------------- ### Initialize VoerkaI18n Project Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/index.md Initializes a new project for internationalization using the VoerkaI18n CLI. This command sets up the necessary configuration files and directory structure for translations. ```shell voerkai18n init ``` -------------------------------- ### Markdown Other Elements Syntax Example Source: https://github.com/zhangfisher/voerka-i18n/blob/master/examples/astro/src/content/blog/markdown-style-guide.md Demonstrates the Markdown syntax for various other HTML elements, including abbreviations (<abbr>), subscripts (<sub>), superscripts (<sup>), keyboard input (<kbd>), and highlights (<mark>). These elements allow for richer text formatting. ```markdown <abbr title="Graphics Interchange Format">GIF</abbr> is a bitmap image format. H<sub>2</sub>O X<sup>n</sup> + Y<sup>n</sup> = Z<sup>n</sup> Press <kbd>CTRL</kbd> + <kbd>ALT</kbd> + <kbd>Delete</kbd> to end the session. Most <mark>salamanders</mark> are nocturnal, and hunt for insects, worms, and other small creatures. ``` -------------------------------- ### Marking Text for Translation in Javascript Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/intro/get-started.md Demonstrates how to use the `t` function to wrap strings that require translation in Javascript files. It supports both simple strings and strings with interpolation variables. ```javascript // index.js console.log(t("中华人民共和国万岁")) console.log(t("中华人民共和国成立于{}",1949)) ``` ```javascript import { t } from "./languages" // Without interpolation variables t("中华人民共和国") // Position interpolation variables t("中华人民共和国{}","万岁") t("中华人民共和国成立于{}年,首都{}",[1949,"北京"]) ``` -------------------------------- ### Markdown Blockquote Syntax Example Source: https://github.com/zhangfisher/voerka-i18n/blob/master/examples/astro/src/content/blog/markdown-style-guide.md Illustrates how to create blockquotes in Markdown, both with and without attribution. This is useful for quoting external content or highlighting specific passages. The syntax uses the '>' character at the beginning of each line. ```markdown > Tiam, ad mint andaepu dandae nostion secatur sequo quae. > **Note** that you can use _Markdown syntax_ within a blockquote. ``` ```markdown > Don't communicate by sharing memory, share memory by communicating.<br> > — <cite>Rob Pike[^1]</cite> ``` -------------------------------- ### Configure Babel for VoerkaI18n Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/integration/babel.md Example JSON configuration for integrating the @voerkai18n/babel plugin into a Babel setup. This typically involves adding the plugin to the 'plugins' array in your Babel configuration file. ```json { "plugins": [ ["@voerkai18n/babel"] ] } ``` -------------------------------- ### Markdown Nested List Syntax Example Source: https://github.com/zhangfisher/voerka-i18n/blob/master/examples/astro/src/content/blog/markdown-style-guide.md Shows how to create nested lists in Markdown, allowing for hierarchical organization of content. Indentation is used to define sub-items within a list. ```markdown - Fruit - Apple - Orange - Banana - Dairy - Milk - Cheese ``` -------------------------------- ### VoerkaI18n Scope Configuration Example (JSON) Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/advanced/scope.md Provides an example of the `languages/settings.json` file, detailing the structure for configuring a scope, including its ID, default and active languages, and a list of supported languages with their names and titles. ```json { "id": "myapp", // Scope ID "default": "zh-CN", // Default language "active": "en-US", // Active language "languages": [ { "name": "zh-CN", "title": "Chinese" }, { "name": "en-US", "title": "English" } ] } ``` -------------------------------- ### Create Svelte Project Source: https://github.com/zhangfisher/voerka-i18n/blob/master/packages/svelte/README.md Commands to create a new Svelte library project. It can be initialized in the current directory or a specified new directory. Requires npx. ```bash npx sv create # create a new project in my-app npx sv create my-app ``` -------------------------------- ### HTML Code Block Syntax Example Source: https://github.com/zhangfisher/voerka-i18n/blob/master/examples/astro/src/content/blog/markdown-style-guide.md Demonstrates how to embed and highlight HTML code within a Markdown document. By using triple backticks and specifying 'html' after the opening backticks, the code is rendered with syntax highlighting, improving readability. ```markdown ```html <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Example HTML5 Document</title> </head> <body> <p>Test</p> </body> </html> ``` ``` -------------------------------- ### Subscribing to Language Change Events Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/intro/get-started.md Shows how to subscribe to language change events to re-render the interface or perform other actions when the language is updated. Event listeners can be attached using `on` method on either `i18nScope` or `VoerkaI18n`. ```javascript import { i18nScope } from "./languages" // Switch to English i18nScope.on("change",(newLanguage)=>{ // Re-render interface here ... }) // VoerkaI18n.on("change",(newLanguage)=>{ // Re-render interface here ... }) ``` -------------------------------- ### Install VoerkaI18n CLI Globally Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/zh/guide/integration/svelte.md Installs the VoerkaI18n command-line interface globally using npm, yarn, or pnpm. This is the first step in initializing the VoerkaI18n project. ```bash npm install -g @voerkai18n/cli ``` ```bash yarn global add @voerkai18n/cli ``` ```bash pnpm add -g @voerkai18n/cli ``` -------------------------------- ### Compile Language Packs Command Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/intro/get-started.md This command compiles the translated JSON language files into usable language packs for the application. It reads from the `translates/messages` directory and generates language files such as `zh.js`, `en.js`, etc., along with an `idMap.js`. ```shell myapp> voerkai18n compile ``` -------------------------------- ### JavaScript: Example Language Files (Initial) Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/advanced/idMap.md Illustrates the initial structure of language files in JavaScript, using full text strings as keys. This format is intuitive but leads to redundancy. ```javascript // en.js { "中华人民共和国":"the people's Republic of China" } // jp.js { "中华人民共和国":"中華人民共和国" } ``` -------------------------------- ### Build SolidStart Project using npm run build Source: https://github.com/zhangfisher/voerka-i18n/blob/master/examples/solid/README.md Command to build a SolidStart application for deployment. This command uses presets to optimize the project for different environments. The default build generates a Node.js app. Requires Node.js and npm. ```bash npm run build ``` -------------------------------- ### Install @voerkai18n/react Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/integration/react.md Installation instructions for the @voerkai18n/react package using npm, yarn, and pnpm. ```shell npm install @voerkai18n/react yarn add @voerkai18n/react pnpm add @voerkai18n/react ``` -------------------------------- ### Markdown Unordered List Syntax Example Source: https://github.com/zhangfisher/voerka-i18n/blob/master/examples/astro/src/content/blog/markdown-style-guide.md Illustrates the syntax for creating unordered lists in Markdown. List items are typically denoted by hyphens '-', asterisks '*', or plus signs '+'. This is used for items where the order does not matter. ```markdown - List item - Another item - And another item ``` -------------------------------- ### Manual Translation JSON Structure Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/intro/get-started.md This JSON structure represents a typical entry in a language file for VoerkaI18n. It includes the original text as the key and translations for different languages as values, along with metadata like source files and an ID. ```json { "欢迎使用VoerkaI18n":{ "en":"<Write the corresponding English translation here>", "de":"<Write the corresponding German translation here>", "jp":"<Write the corresponding Japanese translation here>", "$files":["index.js"], "$id":1 }, "VoerkaI18n是一款非常棒的国际化解决方案":{ "en":"<Write the corresponding English translation here>", "de":"<Write the corresponding German translation here>", "jp":"<Write the corresponding Japanese translation here>", "$files":["index.js"], "$id":2 } } ``` -------------------------------- ### Install VoerkaI18n for SolidJS Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/integration/solid.md Install the `@voerkai18n/solid` package using npm, yarn, or pnpm. ```shell npm install @voerkai18n/solid yarn add @voerkai18n/solid pnpm add @voerkai18n/solid ``` -------------------------------- ### Formatter Configuration Example (ja-JP) Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/use/datetime.md Provides a snippet of the `languages/formatters.json` file, demonstrating the configuration structure for date formatting rules for the 'ja-JP' locale. It includes examples of setting a default format and a specific 'short' format. ```json { "ja-JP":{ "date":{ "format":"<local | iso | gmt | utc | long | short | [template string]>", "short":"<template string>", "format":"<local | iso | gmt | utc | long | short | [template string]>" } } // ...other languages } ``` -------------------------------- ### Install @voerkai18n/plugins Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/tools/plugins.md Install the @voerkai18n/plugins package as a development dependency using npm, yarn, or pnpm. ```bash npm install --save-dev @voerkai18n/plugins ``` ```bash yarn add -D @voerkai18n/plugins ``` ```bash pnpm add -D @voerkai18n/plugins ``` -------------------------------- ### Install @voerkai18n/nextjs Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/integration/nextjs.md Install the Next.js integration package using npm, yarn, or pnpm. ```shell npm install @voerkai18n/nextjs yarn add @voerkai18n/nextjs pnpm add @voerkai18n/nextjs ``` -------------------------------- ### Create Svelte Project using sv CLI Source: https://github.com/zhangfisher/voerka-i18n/blob/master/examples/svelte/README.md These commands demonstrate how to create a new Svelte project. The first command creates a project in the current directory, while the second creates a project named 'my-app'. This requires Node.js and npm (or pnpm/yarn) to be installed. ```bash npx sv create npx sv create my-app ``` -------------------------------- ### Build Svelte Library Source: https://github.com/zhangfisher/voerka-i18n/blob/master/packages/svelte/README.md Command to build the Svelte library for distribution. Requires npm, pnpm, or yarn. ```bash npm run package ``` -------------------------------- ### Install @voerkai18n/babel Plugin Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/integration/babel.md Instructions for installing the @voerkai18n/babel plugin using npm, yarn, or pnpm. This plugin is a development dependency. ```shell npm install @voerkai18n/babel --save-dev yarn add @voerkai18n/babel -D pnpm add @voerkai18n/babel -D ``` -------------------------------- ### Example Paragraph Translation File Structure (HTML) Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/use/paragraph.md This illustrates the structure of an extracted paragraph translation file. Each `<div>` represents a translated segment for a specific language, identified by the `language` attribute. Comments at the top provide metadata about the original source. ```html <!-- id: license scope: file: src\License\index.vue rang: 3:8-8:12 --> <div language="zh-CN"> 版权所有 (c) [年份] [版权持有者] 特此免费授予任何获得本软件及相关文档文件(以下简称"软件")副本的人,不受限制地处理本软件的权限,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售本软件的副本,并允许获得本软件的人这样做,但须满足以下条件: 上述版权声明和本许可声明应包含在本软件的所有副本或重要部分中。 本软件"按原样"提供,不提供任何形式的明示或暗示的担保,包括但不限于对适销性、特定用途适用性和非侵权性的担保。在任何情况下,作者或版权持有者均不对任何索赔、损害或其他责任负责,无论是在合同、侵权或其他行为中产生的,还是与本软件或本软件的使用或其他交易有关的。 </div> <div language="en-US"> Copyright (c) [year] [copyright holder] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. </div> <div language="ru-RU"> [Russian translation would go here] </div> ``` -------------------------------- ### Install VoerkaI18n CLI Tool Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/integration/vue.md Installs the VoerkaI18n command-line interface globally using npm, yarn, or pnpm. This tool is essential for initializing and managing internationalization features. ```bash npm install -g @voerkai18n/cli ``` ```bash yarn global add @voerkai18n/cli ``` ```bash pnpm add -g @voerkai18n/cli ``` -------------------------------- ### Install @voerkai18n/patch using npm, yarn, or pnpm Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/advanced/edit-patch.md These commands show how to install the @voerkai18n/patch package using different package managers (npm, yarn, pnpm). This is the first step before using the library's functionalities. ```shell npm install @voerkai18n/patch ``` ```shell yarn add @voerkai18n/patch ``` ```shell pnpm add @voerkai18n/patch ``` -------------------------------- ### Install VoerkaI18n Webpack Loader Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/integration/webpack.md Installs the @voerkai18n/webpack loader using npm, yarn, or pnpm. This is a development dependency. ```shell npm install @voerkai18n/webpack --save-dev yarn add @voerkai18n/webpack -D pnpm add @voerkai18n/webpack -D ``` -------------------------------- ### Install @voerkai18n/babel Plugin Globally Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/tools/babel.md Installs the @voerkai18n/babel plugin globally using different package managers. This is the first step to enabling automatic text mapping and 't' function import. ```bash npm install -g @voerkai18n/babel ``` ```bash yarn global add @voerkai18n/babel ``` ```bash pnpm add -g @voerkai18n/babel ``` -------------------------------- ### Install @voerkai18n/babel Plugin Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/zh/guide/tools/babel.md Globally install the @voerkai18n/babel plugin using npm, yarn, or pnpm. This plugin is essential for enabling automatic 't' function imports and text mapping in your project. ```bash > npm install -g @voerkai18n/babel ``` ```bash > yarn global add @voerkai18n/babel ``` ```bash > pnpm add -g @voerkai18n/babel ``` -------------------------------- ### Install @voerkai18n/svelte Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/integration/svelte.md Install the @voerkai18n/svelte package using npm, yarn, or pnpm. This is the first step to enable internationalization in your Svelte application. ```shell npm install @voerkai18n/svelte yarn add @voerkai18n/svelte pnpm add @voerkai18n/svelte ``` -------------------------------- ### Publish Svelte Library to npm Source: https://github.com/zhangfisher/voerka-i18n/blob/master/packages/svelte/README.md Command to publish the Svelte library to the npm registry. Ensure the package name and license are correctly configured in 'package.json'. Requires npm. ```bash npm publish ``` -------------------------------- ### Compile Translations with VoerkaI18n Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/index.md Compiles the translated text into a format usable by your application using the VoerkaI18n CLI. This step optimizes the translations for production deployment. ```shell voerkai18n compile ``` -------------------------------- ### Create Astro Blog Project with pnpm Source: https://github.com/zhangfisher/voerka-i18n/blob/master/examples/astro/README.md This command initializes a new Astro project using the blog starter template with pnpm. It sets up the basic structure and dependencies required for a blog. ```sh pnpm create astro@latest -- --template blog ``` -------------------------------- ### VoerkaI18n Workflow Configuration (JSON) Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/advanced/settings.md Example of workflow configuration for VoerkaI18n, specifying the entry directory, namespaces, and file patterns for text extraction. This configuration is typically placed in the 'voerkai18n' field of package.json. ```json { "voerkai18n": { "entry": "src", "namespaces": { "default": "messages" }, "patterns": [ "!**/*.ts" ] } } ``` -------------------------------- ### JavaScript: Compile Paragraphs for Language Packs Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/tools/compile.md Example of paragraph content in JavaScript format for different locales. These are compiled into separate paragraph files. ```javascript // languages/paragraphs/license.js export default { "zh-CN": "...", "en-US": "..." } ``` -------------------------------- ### Enable Vite Plugin for Voerka i18n Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/zh/guide/tools/plugins.md Configuration example for enabling the @voerkai18n/plugins/vite in a vite.config.js file. It demonstrates importing and configuring the plugin, optionally including vite-plugin-inspect for debugging. ```javascript import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import Inspect from 'vite-plugin-inspect'// Optional import Voerkai18nPlugin from "@voerkai18n/plugins/vite" export default defineConfig({ plugins: [ Inspect(), // Optional Voerkai18nPlugin({debug:true}), vue() ] }) ``` -------------------------------- ### Translate Text with VoerkaI18n Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/index.md Initiates the translation process for extracted text using the VoerkaI18n CLI. This command typically integrates with translation files or AI services to perform the translations. ```shell voerkai18n translate ``` -------------------------------- ### Specifying Positional Arguments for Currency (JavaScript) Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/zh/guide/use/currency.md This example demonstrates how to pass various positional arguments to the `currency` formatter to control its output, including format, unit, precision, prefix, suffix, division, and symbol. It shows how to specify these parameters sequentially. ```javascript // t("{ value | currency(<format>,<unit>,<precision>,<prefix>,<suffix>,<division>,<symbol>,<radix>)}",1234.56) t("{ value | currency('long',1)}",1234.56) // 长格式: 万元 t("{ value | currency('long',1,2,'人民币')}",1234.56) t("{ value | currency('long',1,2,'人民币','元',3,'')}",1234.56) ``` -------------------------------- ### Date Formatting Examples with Different Locales Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/use/datetime.md Demonstrates the usage of the 'date' formatter with various predefined and custom formats for 'zh-CN' and 'en-US' locales. This showcases how the same translation key can produce different date outputs based on the active language and specified format. ```javascript t("Now is { value }", NOW) // Expected Output (zh-CN): Now is 2022/8/12 10:12:36 t("Now is { value | date }", NOW) // Expected Output (zh-CN): Now is 2022/8/12 10:12:36 t("Now is { value | date('local') }", NOW) // Expected Output (zh-CN): Now is 2022/8/12 10:12:36 t("Now is { value | date('long') }", NOW) // Expected Output (zh-CN): Now is 2022年08月12日 10点12分36秒 t("Now is { value | date('short') }", NOW) // Expected Output (zh-CN): Now is 2022/08/12 t("Now is { value | date('iso') }", NOW) // Expected Output (zh-CN): Now is 2022-08-12T02:12:36.000Z t("Now is { value | date('gmt') }", NOW) // Expected Output (zh-CN): Now is Fri, 12 Aug 2022 02:12:36 GMT t("Now is { value | date('utc') }", NOW) // Expected Output (zh-CN): Now is Fri, 12 Aug 2022 02:12:36 GMT t("Now is { value | date('YYYY-MM-DD HH:mm:ss')}", NOW) // Expected Output (zh-CN): Now is 2022-08-12 10:12:36 t("Now is { value | date('YYYY/MM/DD') }", NOW) // Expected Output (zh-CN): Now is 2022-08-12 t("Now is { value | date('HH:mm:ss') }", NOW) // Expected Output (zh-CN): 10:12:36 ``` -------------------------------- ### UniApp Setup with VoerkaI18n Vue Plugins Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/integration/uniapp.md Instructions for setting up VoerkaI18n in a UniApp project by importing the appropriate Vue plugin. This ensures internationalization is correctly configured for the UniApp environment, supporting both Vue 2 and Vue 3. ```javascript import { createI18n } from 'vue-i18n' const i18n = createI18n({ // ... other options }) export default i18n ``` ```javascript // For Vue 3 projects: import { createI18n } from '@voerkaI18n/vue' // For Vue 2 projects: import { createI18n } from '@voerkaI18n/vue2' // Then use it as you would in a regular Vue project. ``` -------------------------------- ### Node.js Server-Side Internationalization with VoerkaI18n Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/README.md This example demonstrates how to use VoerkaI18n in a Node.js environment, likely for server-side rendering or API localization. It shows initializing the translation service and using the `t` function. ```javascript const { VoerkaI18n } = require('@voerkai18n/core'); const path = require('path'); async function initI18n() { const i18n = new VoerkaI18n({ defaultLocale: 'en', locales: ['en', 'zh-CN'], directory: path.join(__dirname, 'locales') }); await i18n.init(); return i18n; } async function main() { const i18n = await initI18n(); const message = i18n.t('Hello from Node.js!'); console.log(message); } main(); ``` -------------------------------- ### Extract Text for Translation with VoerkaI18n Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/index.md Extracts translatable text strings from your project files using the VoerkaI18n CLI. This process identifies strings that need to be localized and prepares them for translation. ```shell voerkai18n extract ``` -------------------------------- ### VoerkaI18nScope Constructor Options (TypeScript) Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/reference/i18nscope.md Defines the configuration options for creating a VoerkaI18nScope instance. These options control aspects like message IDs, formatters, storage, language packs, and more, allowing for flexible internationalization setup. ```typescript interface VoerkaI18nScopeOptions{ id?: string // Current scope ID idMap?: VoerkaI18nIdMap // Message ID mapping list formatters?: VoerkaI18nFormatters // Formatters storage?: IVoerkaI18nStorage // Language configuration storage messages?: VoerkaI18nLanguageMessagePack // Language packs paragraphs?: VoerkaI18nParagraphs // Paragraphs component?: VoerkaI18nTranslateComponentBuilder<TranslateComponent> // Translation component loader?: VoerkaI18nLanguageLoader // Message loader transform?: VoerkaI18nTranslateTransformBuilder<TranslateTransformResult> // Transform translation results languages?: VoerkaI18nLanguage[] // Supported languages default?: string // Default language active?: string // Active language fallback?: string // Fallback language debug?: boolean // Whether to enable debug mode injectLangAttr?: boolean | string // Whether to inject language attribute to html element storageKey?: string // Key used when saving current language to Storage cachePatch?: boolean // Whether to cache patch language packs } ``` -------------------------------- ### Astro Project Structure Overview Source: https://github.com/zhangfisher/voerka-i18n/blob/master/examples/astro/README.md This code block displays the typical directory structure of an Astro project. It shows the organization of public assets, source files (components, content, layouts, pages), and configuration files. ```text ├── public/ ├── src/ │ ├── components/ │ ├── content/ │ ├── layouts/ │ └── pages/ ├── astro.config.mjs ├── README.md ├── package.json └── tsconfig.json ``` -------------------------------- ### Translate with Custom Currency Formatting in JavaScript Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/use/currency.md Shows examples of using the `t` function for translation with custom currency formatting in JavaScript. It demonstrates applying a 'bitcoin' format and a custom format with a specified symbol. ```javascript t("I have {value | currency('bitcoin') } bitcoins",12344354) t("I have {value | currency({format:'bitcoin',symbol:'฿') } bitcoins",12344354) ``` -------------------------------- ### Translate Paragraphs Command (Bash) Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/use/paragraph.md This command initiates the translation process for extracted paragraph content. It processes files located in `languages/translates/paragraphs/*.html` and generates translated versions. ```bash > voerkai18n translate ``` -------------------------------- ### Using Predefined Currency Formats (JavaScript) Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/zh/guide/use/currency.md Demonstrates the use of predefined `format` options ('long', 'short', 'default', 'custom') within the `currency` formatter. The output varies based on the locale, with examples provided for Chinese and English, showcasing how predefined templates are applied. ```javascript t("{ value | currency('long')}",1234.56) // == 长格式输出: RMB¥1234.56元 t("{ value | currency('short')}",1234.56) // ==短格式输出 ¥1234.56 await scope.change("en") t("{ value | currency('long')}",1234.56) // == $1,234.56 t("{ value | currency('short')}",1234.56) // == USD $1,234.56 ``` -------------------------------- ### Import Translation Function in JavaScript Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/intro/get-started.md This demonstrates how to import the translation function 't' into your JavaScript files. This function is typically generated during the compilation phase and is located in `myapp/languages/index.js`. It's used to wrap text that needs translation. ```javascript import { t } from "./languages" ``` -------------------------------- ### Customizing Currency Format Template (JavaScript) Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/zh/guide/use/currency.md This example shows how to define a custom format string for the `currency` formatter. By using placeholders like `{prefix}`, `{symbol}`, `{value}`, `{unit}`, and `{suffix}`, you can create flexible currency output structures tailored to specific needs or languages. ```javascript - format = "{symbol} {value}{unit}" ==> ¥ 123.45元 - format = "{prefix} {symbol} {value}{unit}" ==> 人民币:¥123.45元 ``` -------------------------------- ### Configure Server-Side Translation in Next.js Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/zh/guide/integration/nextjs.md This TypeScript code snippet illustrates the manual setup for server-side internationalization within a Next.js application using VoerkaI18n. It configures the translate component and the i18nScope with server-specific messages and settings. Ensure that `@voerkai18n/nextjs/server` is installed. ```typescript import { createServerTranslateComponent, ReactServerTranslateComponentType } from "@voerkai18n/nextjs/server" import { VoerkaI18nScope, VoerkaI18nTranslateProps } from '@voerkai18n/runtime'; import formatters from "@voerkai18n/formatters" import storage from "./storage" import idMap from "./messages/idMap.json" import paragraphs from "./paragraphs" import settings from "./settings.json" import zhCNMessages from "./messages/zh-CN" import enUSMessages from "./messages/en-US"; import jaJPMessages from "./messages/ja-JP"; const component = createServerTranslateComponent() const messages = { 'zh-CN' : zhCNMessages, 'en-US' : enUSMessages, 'ja-JP' : jaJPMessages } export const i18nScope = new VoerkaI18nScope<ReactServerTranslateComponentType>({ id: "nextjs_server", // 当前作用域的id injectLangAttr:false, // 不注入lang属性 idMap, // 消息id映射列表 formatters, // 格式化器 storage, // 语言配置存储器 messages, // 语言包 paragraphs, component, // 翻译组件 ...settings }) export const t = i18nScope.t export const Translate = i18nScope.Translate as React.FC<VoerkaI18nTranslateProps> ``` -------------------------------- ### VoerkaI18n CLI Help and Commands Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/zh/guide/tools/cli.md Displays the help information and lists the available commands for the VoerkaI18n CLI. This includes commands for initialization, extraction, compilation, translation, wrapping, inspection, and application. ```shell __ __ _ ___ _ ___ \ \ / /__ _ __| | ____ _|_ _/ |( _ ) _ __ \ \ / / __/ | | |/ / _\` || || |/ _ \| '_ \ \ V / __/ | | < (_| || || | (_) | | | | \_/ \___|_| |_|\_\__,_|___|_|\___/|_| |_| Voerkai18n Version: 3.0.6 Usage: voerkai18n [options] [command] Options: -h, --help display help for command Commands: init|config [options] 初始化VoerkaI18n配置 extract [options] 提取要翻译的文本 compile [options] 编译语言包 translate [options] 执行自动翻译 wrap [options] 扫描源代码并为需要翻译的内容自动包裹t翻译函数 inspect [options] 检查VoerkaI18n配置 apply [options] 配置vue/react/nextjs/svelte等支持 ``` -------------------------------- ### HTML5 Application Cache Manifest for Language Packs Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/en/guide/advanced/lang-pack.md Provides an example of an HTML5 CACHE MANIFEST file used to optimize asynchronous language pack loading. By listing asynchronous language pack chunks in the manifest, browsers can pre-cache these files, eliminating loading delays for users. ```nginx CACHE MANIFEST # Version 1.1 // Add chunk files corresponding to asynchronous language packs here ``` -------------------------------- ### init | config Command Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/zh/guide/tools/cli.md Initializes VoerkaI18n configuration in a project, creating language directories and configuration files. ```APIDOC ## Initialize - init Initializes VoerkaI18n in the specified project, creating corresponding language working directories and configuration files. ```shell Usage: voerkai18n init|config [options] 初始化VoerkaI18n配置 Options: -d, --language-dir [path] 语言目录 (default: "src\\languages") --library 是否开发库工程 -l, --languages <tags...> 选择支持的语言 --defaultLanguage <tag> 默认语言 --activeLanguage <tag> 激活语言 -t, --typescript 启用Typescript (default: true) -h, --help display help for command ``` Executing `voerkai18n init` in the project root will create the configuration file within the current project. **Example Directory Structure After Initialization:** <lite-tree> myapp //i src languages //* api.json // 翻译相关API声明 component.ts // 翻译组件 index.ts //! 入口文件 messages/ // 编译后的语言包 paragraphs/ // 编译后的段落 prompts/ // AI翻译所用的提示词 settings.json //! 配置文件 storage.ts // 存储 loader.ts // 语言加载器 transform.ts // 翻译转换器 formatters.json // 格式化器配置 translates/ // 提取需要翻译的内容到此 package.json //i index.ts //i </lite-tree> - The `settings.json` configuration is created based on user prompts during initialization, primarily for configuring supported languages and basic information. - The `init` command also has a `config` alias, making them equivalent. You can re-run `voerkai18n config` after `init` to update the configuration. ``` -------------------------------- ### Integrate unplugin-starter with esbuild Source: https://github.com/zhangfisher/voerka-i18n/blob/master/packages/plugins/README.md Configures esbuild to use the unplugin-starter plugin. This involves importing the plugin and including it in the esbuild build options' plugins array. ```typescript // esbuild.config.js import { build } from 'esbuild' import Starter from 'unplugin-starter/esbuild' build({ plugins: [Starter()], }) ``` -------------------------------- ### Integrate unplugin-starter with Nuxt Source: https://github.com/zhangfisher/voerka-i18n/blob/master/packages/plugins/README.md Configures Nuxt to use the unplugin-starter plugin as a module. This is compatible with both Nuxt 2 and Nuxt Vite. ```javascript // nuxt.config.js export default defineNuxtConfig({ modules: [ ['unplugin-starter/nuxt', { /* options */ }], ], }) ``` -------------------------------- ### Integrate unplugin-starter with Vite Source: https://github.com/zhangfisher/voerka-i18n/blob/master/packages/plugins/README.md Configures Vite to use the unplugin-starter plugin. This involves importing the plugin and adding it to the Vite configuration's plugins array. ```typescript // vite.config.ts import Starter from 'unplugin-starter/vite' export default defineConfig({ plugins: [ Starter({ /* options */ }), ], }) ``` -------------------------------- ### Integrate unplugin-starter with Rollup Source: https://github.com/zhangfisher/voerka-i18n/blob/master/packages/plugins/README.md Configures Rollup to use the unplugin-starter plugin. This involves importing the plugin and adding it to the Rollup configuration's plugins array. ```javascript // rollup.config.js import Starter from 'unplugin-starter/rollup' export default { plugins: [ Starter({ /* options */ }), ], } ``` -------------------------------- ### Initialize VoerkaI18n Project Source: https://github.com/zhangfisher/voerka-i18n/blob/master/docs/zh/guide/integration/svelte.md Initializes a new VoerkaI18n project, creating a language working directory (defaulting to 'src/languages') with a predefined structure for translations, prompts, API definitions, and configuration files. ```bash > voerkai18n init ```