├── .eslintignore ├── .eslintrc.json ├── .github ├── release.yml └── workflows │ ├── pages-deploy.yml │ └── pull-request.yml ├── .gitignore ├── .prettierignore ├── .prettierrc ├── .tool-versions ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── README_zh.md ├── dev ├── App.vue ├── components │ ├── DemoAlert.vue │ ├── DemoCustomTags.vue │ ├── DemoDateFormat.vue │ ├── DemoDirective.vue │ ├── DemoIf.vue │ ├── DemoMultilines.vue │ ├── DemoPlural.vue │ ├── DemoTemplate.vue │ └── LanguageSelect.vue ├── gettext.d.ts ├── i18n.ts ├── index.html ├── language │ ├── LINGUAS │ ├── en_GB │ │ └── app.po │ ├── fr_FR │ │ └── app.po │ ├── it_IT │ │ └── app.po │ ├── messages.pot │ ├── translations.json │ └── zh_CN │ │ └── app.po ├── main.ts ├── tsconfig.json ├── variables.css └── vite.config.ts ├── docs ├── .vuepress │ ├── client.ts │ ├── config.ts │ └── styles │ │ └── index.scss ├── README.md ├── component.md ├── configuration.md ├── demo.md ├── directive.md ├── extraction.md ├── functions.md ├── setup.md ├── translation.md └── zh │ ├── README.md │ ├── component.md │ ├── configuration.md │ ├── demo.md │ ├── directive.md │ ├── extraction.md │ ├── functions.md │ ├── setup.md │ └── translation.md ├── gettext.config.js ├── package-lock.json ├── package.json ├── scripts ├── attributeEmbeddedJsExtractor.ts ├── compile.ts ├── config.ts ├── embeddedJsExtractor.ts ├── extract.ts ├── gettext_compile.ts ├── gettext_extract.ts └── utils.ts ├── src ├── component.ts ├── directive.ts ├── index.ts ├── interpolate.ts ├── plurals.ts ├── translate.ts ├── typeDefs.ts └── utilities.ts ├── tests ├── component.spec.ts ├── config.test.ts ├── directive.arabic.spec.ts ├── directive.spec.ts ├── interpolate.spec.ts ├── json │ ├── component.ts │ ├── directive.arabic.ts │ ├── directive.ts │ ├── plugin.config.ts │ └── translate.ts ├── plurals.spec.ts ├── translate.spec.ts └── utils.ts ├── tsconfig.json ├── tsup.config.ts └── vitest.config.ts /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | distDocs 4 | coverage 5 | dev/language 6 | docs/language/translations.json 7 | docs/.vuepress/.cache 8 | docs/.vuepress/.temp 9 | .vscode 10 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "env": { 4 | "node": true 5 | }, 6 | "extends": ["plugin:vue/vue3-recommended", "prettier"], 7 | "rules": {}, 8 | "parserOptions": { 9 | "parser": "@typescript-eslint/parser", 10 | "sourceType": "module", 11 | "ecmaVersion": 2020 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.github/release.yml: -------------------------------------------------------------------------------- 1 | changelog: 2 | categories: 3 | - title: BREAKING CHANGES 💣 4 | labels: 5 | - breaking-change 6 | - title: Enhancements ✨ 7 | labels: 8 | - enhancement 9 | - title: Fixes 10 | labels: 11 | - bug -------------------------------------------------------------------------------- /.github/workflows/pages-deploy.yml: -------------------------------------------------------------------------------- 1 | name: pages 2 | on: 3 | push: 4 | branches: 5 | - master 6 | jobs: 7 | build-and-deploy: 8 | runs-on: ubuntu-20.04 9 | steps: 10 | - name: checkout 11 | uses: actions/checkout@v2.3.5 12 | 13 | - name: build 14 | run: | 15 | npm ci 16 | npm run docs:build 17 | 18 | - name: deploy 19 | uses: JamesIves/github-pages-deploy-action@4.1.5 20 | with: 21 | branch: pages 22 | folder: distDocs 23 | -------------------------------------------------------------------------------- /.github/workflows/pull-request.yml: -------------------------------------------------------------------------------- 1 | name: pull request 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - master 7 | types: [opened, edited, reopened, synchronize] 8 | 9 | jobs: 10 | test: 11 | name: "test" 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - name: check out repo 16 | uses: actions/checkout@v3 17 | - name: setup node 18 | id: setup-node 19 | uses: actions/setup-node@v3 20 | with: 21 | node-version: 18 22 | - name: install system dependencies 23 | run: | 24 | sudo apt-get update 25 | sudo apt-get install -y gettext 26 | - name: install npm dependencies 27 | run: npm ci 28 | - name: run tests 29 | run: npm run test 30 | - name: build package 31 | run: npm run build 32 | - name: build docs 33 | run: npm run docs:build 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.tmp/ 2 | /node_modules/ 3 | dist 4 | distDocs 5 | npm-debug.log 6 | manifest.json 7 | *.DS_Store 8 | *~ 9 | .*.swp 10 | .*.pid 11 | *.mo 12 | ./coverage 13 | .yarn 14 | yarn.lock 15 | 16 | .tm_properties 17 | .idea/ 18 | 19 | docs/.vuepress/.cache 20 | docs/.vuepress/.temp 21 | .npmrc 22 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | coverage 4 | dev/language 5 | docs/language/translations.json 6 | docs/.vuepress/.cache 7 | docs/.vuepress/.temp 8 | distDocs 9 | .vscode 10 | .eslintrc.json 11 | package.json 12 | package-lock.json 13 | tsconfig.json -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "arrowParens": "always", 4 | "trailingComma": "all" 5 | } 6 | -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | nodejs 20.14.0 2 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "node_modules/typescript/lib" 3 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 JOSHMARTIN GmbH 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Vue 3 Gettext 💬 4 | 5 |

6 |
7 | 8 | Translate [Vue 3](http://vuejs.org) applications with [gettext](https://en.wikipedia.org/wiki/Gettext). 9 | 10 |
11 |

12 | Getting started | Demo | Documentation | 中文 13 |

14 |
15 | 16 | ## Basic usage 17 | 18 | In templates: 19 | 20 | ```jsx 21 | 22 | {{ $gettext("I'm %{age} years old!", { age: 32 }) }} 23 | 24 | ``` 25 | 26 | In code: 27 | 28 | ```ts 29 | const { $gettext } = useGettext(); 30 | 31 | console.log($gettext("Hello World!")); 32 | ``` 33 | 34 | ## Features 35 | 36 | - simple, ergonomic API 37 | - reactive translations in Vue templates and TypeScript/JavaScript code 38 | - CLI to automatically extract messages from code files 39 | - support for pluralization and message contexts 40 | 41 | ## Contribute 42 | 43 | Please make sure your code is properly formatted (the project contains a `prettier` config) and all the tests run successfully (`npm run test`) when opening a pull request. 44 | 45 | Please specify clearly what you changed and why. 46 | 47 | ## Credits 48 | 49 | This plugin relies heavily on the work of the original [`vue-gettext`](https://github.com/Polyconseil/vue-gettext/). 50 | 51 | ## License 52 | 53 | [MIT](http://opensource.org/licenses/MIT) 54 | -------------------------------------------------------------------------------- /README_zh.md: -------------------------------------------------------------------------------- 1 |

2 | Vue 3 Gettext 💬 3 |

4 |
5 | 6 | 使用 [gettext](https://en.wikipedia.org/wiki/Gettext) 国际化 [Vue 3](http://vuejs.org) 应用程序。 7 | 8 |
9 |

10 | 快速上手 | 在线演示 | 使用文档 | English 11 |

12 |
13 | 14 | ## 基本用法 15 | 16 | 模版: 17 | 18 | ```jsx 19 | 20 | {{ $gettext("I'm %{age} years old!", { age: 32 }) }} 21 | 22 | ``` 23 | 24 | 代码: 25 | 26 | ```ts 27 | const { $gettext } = useGettext(); 28 | 29 | console.log($gettext("Hello World!")); 30 | ``` 31 | 32 | ## 特性 33 | 34 | - 简单、符合人体工学的 API 接口 35 | - 支持响应式翻译(Vue 模板和 TypeScript/JavaScript 代码) 36 | - 提供 CLI 工具自动从代码文件中提取翻译文本 37 | - 支持复数和上下文翻译 38 | 39 | ## 贡献 40 | 41 | 提交 PR 前请确保代码已经格式化(项目中已有 `prettier` 配置),而且测试(`npm run test`)已通过。 42 | 43 | 并且写清楚改了什么以及为什么要这样改。 44 | 45 | 46 | ## 致谢 47 | 本项目在很大程度上依赖于 [`vue-gettext`](https://github.com/Polyconseil/vue-gettext/) 所做的工作. 48 | 49 | ## License 50 | 51 | [MIT](http://opensource.org/licenses/MIT) 52 | -------------------------------------------------------------------------------- /dev/App.vue: -------------------------------------------------------------------------------- 1 | 42 | 43 | 80 | 81 | 110 | -------------------------------------------------------------------------------- /dev/components/DemoAlert.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 41 | -------------------------------------------------------------------------------- /dev/components/DemoCustomTags.vue: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /dev/components/DemoDateFormat.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 29 | -------------------------------------------------------------------------------- /dev/components/DemoDirective.vue: -------------------------------------------------------------------------------- 1 | 27 | 28 | 46 | -------------------------------------------------------------------------------- /dev/components/DemoIf.vue: -------------------------------------------------------------------------------- 1 | 20 | 21 | 45 | -------------------------------------------------------------------------------- /dev/components/DemoMultilines.vue: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /dev/components/DemoPlural.vue: -------------------------------------------------------------------------------- 1 | 28 | 29 | 51 | -------------------------------------------------------------------------------- /dev/components/DemoTemplate.vue: -------------------------------------------------------------------------------- 1 | 19 | 20 | 31 | -------------------------------------------------------------------------------- /dev/components/LanguageSelect.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 25 | 26 | 33 | -------------------------------------------------------------------------------- /dev/gettext.d.ts: -------------------------------------------------------------------------------- 1 | export {}; 2 | declare module "@vue/runtime-core" { 3 | interface ComponentCustomProperties { 4 | __: ComponentCustomProperties["$gettext"]; 5 | _x: ComponentCustomProperties["$pgettext"]; 6 | _n: ComponentCustomProperties["$ngettext"]; 7 | _xn: ComponentCustomProperties["$npgettext"]; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /dev/i18n.ts: -------------------------------------------------------------------------------- 1 | import translations from "./language/translations.json"; 2 | import { createGettext } from "/@gettext/"; 3 | 4 | const gettext = createGettext({ 5 | availableLanguages: { 6 | en_GB: "British English", 7 | fr_FR: "Français", 8 | it_IT: "Italiano", 9 | zh_CN: "简体中文", 10 | }, 11 | defaultLanguage: "en_GB", 12 | translations: translations, 13 | setGlobalProperties: true, 14 | globalProperties: { 15 | // custom global properties name 16 | gettext: ["$gettext", "__"], 17 | ngettext: ["$ngettext", "_n"], 18 | pgettext: ["$pgettext", "_x"], 19 | npgettext: ["$npgettext", "_xn"], 20 | }, 21 | }); 22 | 23 | export { gettext }; 24 | -------------------------------------------------------------------------------- /dev/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | vue3-gettext example 7 | 8 | 9 |
10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /dev/language/LINGUAS: -------------------------------------------------------------------------------- 1 | en_GB fr_FR it_IT zh_CN -------------------------------------------------------------------------------- /dev/language/en_GB/app.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: \n" 4 | "Last-Translator: Automatically generated\n" 5 | "Language-Team: none\n" 6 | "Language: en_GB\n" 7 | "MIME-Version: 1.0\n" 8 | "Content-Type: text/plain; charset=UTF-8\n" 9 | "Content-Transfer-Encoding: 8bit\n" 10 | "Generated-By: easygettext\n" 11 | "Plural-Forms: nplurals=2; plural=(n != 1);\n" 12 | 13 | #: dev/components/DemoPlural.vue:18 14 | msgid "%{ countForUntranslated } item. This is left untranslated on purpose." 15 | msgid_plural "" 16 | "%{ countForUntranslated } items. This is left untranslated on purpose." 17 | msgstr[0] "" 18 | "%{ countForUntranslated } item. This is left untranslated on purpose." 19 | msgstr[1] "" 20 | "%{ countForUntranslated } items. This is left untranslated on purpose." 21 | 22 | #: dev/components/DemoPlural.vue:12 23 | msgid "%{ n } book" 24 | msgid_plural "%{ n } books" 25 | msgstr[0] "%{ n } book" 26 | msgstr[1] "%{ n } books" 27 | 28 | #: dev/components/DemoAlert.vue:35 29 | #, fuzzy 30 | msgid "%{ n } car" 31 | msgid_plural "%{ n } cars" 32 | msgstr[0] "%{ n } book" 33 | msgstr[1] "%{ n } books" 34 | 35 | #: dev/components/DemoDirective.vue:15 36 | msgid "%{ count } apple" 37 | msgid_plural "%{ count } apples" 38 | msgstr[0] "%{ count } apple" 39 | msgstr[1] "%{ count } apples" 40 | 41 | #: dev/components/DemoDirective.vue:4 42 | msgid "A random number: %{ random }" 43 | msgstr "A random number: %{ random }" 44 | 45 | #: dev/components/DemoMultilines.vue:3 46 | msgid "" 47 | "Forgotten your password? Enter your \"email address\" below, and we'll email " 48 | "instructions for setting a new one." 49 | msgstr "" 50 | "Forgotten your password? Enter your \"email address\" below,\n" 51 | " and we'll email instructions for setting a new one." 52 | 53 | #. use jsExtractorOpts in gettext.config.js to extract custom keywords 54 | #: dev/components/DemoAlert.vue:24 55 | msgid "Good bye!" 56 | msgstr "" 57 | 58 | #: dev/components/DemoCustomTags.vue:3 59 | msgid "Headline 1" 60 | msgstr "Headline 1" 61 | 62 | #: dev/components/DemoCustomTags.vue:4 63 | msgid "Headline 2" 64 | msgstr "Headline 2" 65 | 66 | #: dev/components/DemoCustomTags.vue:5 67 | msgid "Headline 3" 68 | msgstr "Headline 3" 69 | 70 | #: dev/components/DemoCustomTags.vue:6 71 | msgid "Headline 4" 72 | msgstr "Headline 4" 73 | 74 | #: dev/components/DemoDirective.vue:9 75 | msgid "Hello %{ name }" 76 | msgstr "Hello %{ name }" 77 | 78 | #: dev/components/DemoTemplate.vue:11 79 | msgid "hover here and see the title" 80 | msgstr "" 81 | 82 | #: dev/components/DemoPlural.vue:4 83 | msgid "In English, '0' (zero) is always plural." 84 | msgstr "In English, '0' (zero) is always plural." 85 | 86 | #: dev/components/DemoTemplate.vue:7 87 | msgid "One apple" 88 | msgid_plural "%{n} apples" 89 | msgstr[0] "" 90 | msgstr[1] "" 91 | 92 | #: dev/components/DemoCustomTags.vue:7 93 | msgid "Paragraph" 94 | msgstr "Paragraph" 95 | 96 | #: dev/components/LanguageSelect.vue:4 97 | msgid "Select your language:" 98 | msgstr "Select your language:" 99 | 100 | #: dev/components/DemoIf.vue:14 dev/components/DemoIf.vue:15 101 | #: dev/components/DemoIf.vue:16 102 | msgid "This is %{ obj.name }" 103 | msgstr "This is %{ obj.name }" 104 | 105 | #: dev/components/DemoTemplate.vue:4 106 | msgid "use `__` as a alias of gettext" 107 | msgstr "" 108 | 109 | #: dev/components/DemoTemplate.vue:6 110 | msgid "use `_n` as a alias of ngettext" 111 | msgstr "" 112 | 113 | #: dev/components/DemoTemplate.vue:10 114 | msgid "use `_x` as a alias of pgettext" 115 | msgstr "" 116 | 117 | #: dev/components/DemoTemplate.vue:14 118 | msgid "use `_xn` as a alias of npgettext" 119 | msgstr "" 120 | 121 | #: dev/components/DemoIf.vue:5 122 | msgid "Welcome %{ name }" 123 | msgstr "Welcome %{ name }" 124 | 125 | #: dev/components/DemoTemplate.vue:15 126 | msgctxt "list-item" 127 | msgid "one message" 128 | msgid_plural "%{n} messages" 129 | msgstr[0] "" 130 | msgstr[1] "" 131 | 132 | #: dev/components/DemoTemplate.vue:9 133 | msgctxt "title" 134 | msgid "This is my title" 135 | msgstr "" 136 | 137 | #~ msgid "%{ nComputed } book" 138 | #~ msgid_plural "%{ nComputed } books" 139 | #~ msgstr[0] "%{ nComputed } book" 140 | #~ msgstr[1] "%{ nComputed } books" 141 | 142 | #~ msgid "" 143 | #~ "Use default singular or plural form when there is no translation. This is " 144 | #~ "left untranslated on purpose." 145 | #~ msgstr "" 146 | #~ "Use default singular or plural form when there is no translation. This is " 147 | #~ "left untranslated on purpose." 148 | -------------------------------------------------------------------------------- /dev/language/fr_FR/app.po: -------------------------------------------------------------------------------- 1 | # French translations for vue-gettext package 2 | # Traductions françaises du paquet vue-gettext. 3 | # Copyright (C) 2016 THE vue-gettext'S COPYRIGHT HOLDER 4 | # This file is distributed under the same license as the vue-gettext package. 5 | # Automatically generated, 2016. 6 | # 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: vue-gettext 2.0.0\n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2017-06-13 15:49+0200\n" 12 | "PO-Revision-Date: 2016-11-22 16:24+0100\n" 13 | "Last-Translator: Automatically generated\n" 14 | "Language-Team: none\n" 15 | "Language: fr_FR\n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=UTF-8\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | "Plural-Forms: nplurals=2; plural=(n > 1);\n" 20 | 21 | #: dev/components/DemoPlural.vue:18 22 | msgid "%{ countForUntranslated } item. This is left untranslated on purpose." 23 | msgid_plural "" 24 | "%{ countForUntranslated } items. This is left untranslated on purpose." 25 | msgstr[0] "" 26 | msgstr[1] "" 27 | 28 | #: dev/components/DemoPlural.vue:12 29 | msgid "%{ n } book" 30 | msgid_plural "%{ n } books" 31 | msgstr[0] "%{ n } livre" 32 | msgstr[1] "%{ n } livres" 33 | 34 | #: dev/components/DemoAlert.vue:35 35 | msgid "%{ n } car" 36 | msgid_plural "%{ n } cars" 37 | msgstr[0] "%{ n } voiture" 38 | msgstr[1] "%{ n } voitures" 39 | 40 | #: dev/components/DemoDirective.vue:15 41 | msgid "%{ count } apple" 42 | msgid_plural "%{ count } apples" 43 | msgstr[0] "%{ count } pomme" 44 | msgstr[1] "%{ count } pommes" 45 | 46 | #: dev/components/DemoDirective.vue:4 47 | msgid "A random number: %{ random }" 48 | msgstr "Un nombre aléatoire : %{ random }" 49 | 50 | #: dev/components/DemoMultilines.vue:3 51 | msgid "" 52 | "Forgotten your password? Enter your \"email address\" below, and we'll email " 53 | "instructions for setting a new one." 54 | msgstr "" 55 | "Mot de passe perdu ? Saisissez votre \"adresse électronique\" ci-dessous\n" 56 | "et nous vous enverrons les instructions pour en créer un nouveau." 57 | 58 | #. use jsExtractorOpts in gettext.config.js to extract custom keywords 59 | #: dev/components/DemoAlert.vue:24 60 | msgid "Good bye!" 61 | msgstr "Au revoir !" 62 | 63 | #: dev/components/DemoCustomTags.vue:3 64 | msgid "Headline 1" 65 | msgstr "Titre 1" 66 | 67 | #: dev/components/DemoCustomTags.vue:4 68 | msgid "Headline 2" 69 | msgstr "Titre 2" 70 | 71 | #: dev/components/DemoCustomTags.vue:5 72 | msgid "Headline 3" 73 | msgstr "Titre 3" 74 | 75 | #: dev/components/DemoCustomTags.vue:6 76 | msgid "Headline 4" 77 | msgstr "Titre 4" 78 | 79 | #: dev/components/DemoDirective.vue:9 80 | msgid "Hello %{ name }" 81 | msgstr "Bonjour %{ name }" 82 | 83 | #: dev/components/DemoTemplate.vue:11 84 | msgid "hover here and see the title" 85 | msgstr "" 86 | 87 | #: dev/components/DemoPlural.vue:4 88 | msgid "In English, '0' (zero) is always plural." 89 | msgstr "En anglais, '0' (zero) prend toujours le pluriel." 90 | 91 | #: dev/components/DemoTemplate.vue:7 92 | msgid "One apple" 93 | msgid_plural "%{n} apples" 94 | msgstr[0] "" 95 | msgstr[1] "" 96 | 97 | #: dev/components/DemoCustomTags.vue:7 98 | msgid "Paragraph" 99 | msgstr "Paragraphe" 100 | 101 | #: dev/components/LanguageSelect.vue:4 102 | msgid "Select your language:" 103 | msgstr "Sélectionner votre langage" 104 | 105 | #: dev/components/DemoIf.vue:14 dev/components/DemoIf.vue:15 106 | #: dev/components/DemoIf.vue:16 107 | msgid "This is %{ obj.name }" 108 | msgstr "C'est %{ obj.name }" 109 | 110 | #: dev/components/DemoTemplate.vue:4 111 | msgid "use `__` as a alias of gettext" 112 | msgstr "" 113 | 114 | #: dev/components/DemoTemplate.vue:6 115 | msgid "use `_n` as a alias of ngettext" 116 | msgstr "" 117 | 118 | #: dev/components/DemoTemplate.vue:10 119 | msgid "use `_x` as a alias of pgettext" 120 | msgstr "" 121 | 122 | #: dev/components/DemoTemplate.vue:14 123 | msgid "use `_xn` as a alias of npgettext" 124 | msgstr "" 125 | 126 | #: dev/components/DemoIf.vue:5 127 | msgid "Welcome %{ name }" 128 | msgstr "Bienvenue %{ name }" 129 | 130 | #: dev/components/DemoTemplate.vue:15 131 | msgctxt "list-item" 132 | msgid "one message" 133 | msgid_plural "%{n} messages" 134 | msgstr[0] "" 135 | msgstr[1] "" 136 | 137 | #: dev/components/DemoTemplate.vue:9 138 | msgctxt "title" 139 | msgid "This is my title" 140 | msgstr "" 141 | 142 | #~ msgid "%{ nComputed } book" 143 | #~ msgid_plural "%{ nComputed } books" 144 | #~ msgstr[0] "%{ nComputed } livre" 145 | #~ msgstr[1] "%{ nComputed } livres" 146 | -------------------------------------------------------------------------------- /dev/language/it_IT/app.po: -------------------------------------------------------------------------------- 1 | # Italian translations for vue-gettext package 2 | # Traduzioni italiane per il pacchetto vue-gettext.. 3 | # Copyright (C) 2016 THE vue-gettext'S COPYRIGHT HOLDER 4 | # This file is distributed under the same license as the vue-gettext package. 5 | # Automatically generated, 2016. 6 | # 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: vue-gettext 2.0.0\n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2017-06-13 15:49+0200\n" 12 | "PO-Revision-Date: 2016-11-22 16:26+0100\n" 13 | "Last-Translator: Automatically generated\n" 14 | "Language-Team: none\n" 15 | "Language: it_IT\n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=UTF-8\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | "Plural-Forms: nplurals=2; plural=(n != 1);\n" 20 | 21 | #: dev/components/DemoPlural.vue:18 22 | msgid "%{ countForUntranslated } item. This is left untranslated on purpose." 23 | msgid_plural "" 24 | "%{ countForUntranslated } items. This is left untranslated on purpose." 25 | msgstr[0] "" 26 | msgstr[1] "" 27 | 28 | #: dev/components/DemoPlural.vue:12 29 | msgid "%{ n } book" 30 | msgid_plural "%{ n } books" 31 | msgstr[0] "%{ n } libbra" 32 | msgstr[1] "%{ n } libri" 33 | 34 | #: dev/components/DemoAlert.vue:35 35 | msgid "%{ n } car" 36 | msgid_plural "%{ n } cars" 37 | msgstr[0] "%{ n } auto" 38 | msgstr[1] "%{ n } auto" 39 | 40 | #: dev/components/DemoDirective.vue:15 41 | msgid "%{ count } apple" 42 | msgid_plural "%{ count } apples" 43 | msgstr[0] "%{ count } mela" 44 | msgstr[1] "%{ count } mele" 45 | 46 | #: dev/components/DemoDirective.vue:4 47 | msgid "A random number: %{ random }" 48 | msgstr "Un numero casuale: %{ random }" 49 | 50 | #: dev/components/DemoMultilines.vue:3 51 | msgid "" 52 | "Forgotten your password? Enter your \"email address\" below, and we'll email " 53 | "instructions for setting a new one." 54 | msgstr "" 55 | "Password dimenticata? Inserisci il tuo \"indirizzo email\" qui\n" 56 | "sotto, e ti invieremo istruzioni per impostarne una nuova." 57 | 58 | #. use jsExtractorOpts in gettext.config.js to extract custom keywords 59 | #: dev/components/DemoAlert.vue:24 60 | msgid "Good bye!" 61 | msgstr "Arriverdeci!" 62 | 63 | #: dev/components/DemoCustomTags.vue:3 64 | msgid "Headline 1" 65 | msgstr "Titolo 1" 66 | 67 | #: dev/components/DemoCustomTags.vue:4 68 | msgid "Headline 2" 69 | msgstr "Titolo 2" 70 | 71 | #: dev/components/DemoCustomTags.vue:5 72 | msgid "Headline 3" 73 | msgstr "Titolo 3" 74 | 75 | #: dev/components/DemoCustomTags.vue:6 76 | msgid "Headline 4" 77 | msgstr "Titolo 4" 78 | 79 | #: dev/components/DemoDirective.vue:9 80 | msgid "Hello %{ name }" 81 | msgstr "Buongiorno %{ name }" 82 | 83 | #: dev/components/DemoTemplate.vue:11 84 | msgid "hover here and see the title" 85 | msgstr "" 86 | 87 | #: dev/components/DemoPlural.vue:4 88 | msgid "In English, '0' (zero) is always plural." 89 | msgstr "In inglese, '0' (zero) è sempre al plurale." 90 | 91 | #: dev/components/DemoTemplate.vue:7 92 | msgid "One apple" 93 | msgid_plural "%{n} apples" 94 | msgstr[0] "" 95 | msgstr[1] "" 96 | 97 | #: dev/components/DemoCustomTags.vue:7 98 | msgid "Paragraph" 99 | msgstr "Paragrafo" 100 | 101 | #: dev/components/LanguageSelect.vue:4 102 | msgid "Select your language:" 103 | msgstr "Seleziona la tua lingua:" 104 | 105 | #: dev/components/DemoIf.vue:14 dev/components/DemoIf.vue:15 106 | #: dev/components/DemoIf.vue:16 107 | msgid "This is %{ obj.name }" 108 | msgstr "Questo è %{ obj.name }" 109 | 110 | #: dev/components/DemoTemplate.vue:4 111 | msgid "use `__` as a alias of gettext" 112 | msgstr "" 113 | 114 | #: dev/components/DemoTemplate.vue:6 115 | msgid "use `_n` as a alias of ngettext" 116 | msgstr "" 117 | 118 | #: dev/components/DemoTemplate.vue:10 119 | msgid "use `_x` as a alias of pgettext" 120 | msgstr "" 121 | 122 | #: dev/components/DemoTemplate.vue:14 123 | msgid "use `_xn` as a alias of npgettext" 124 | msgstr "" 125 | 126 | #: dev/components/DemoIf.vue:5 127 | msgid "Welcome %{ name }" 128 | msgstr "Benvenuto %{ name }" 129 | 130 | #: dev/components/DemoTemplate.vue:15 131 | msgctxt "list-item" 132 | msgid "one message" 133 | msgid_plural "%{n} messages" 134 | msgstr[0] "" 135 | msgstr[1] "" 136 | 137 | #: dev/components/DemoTemplate.vue:9 138 | msgctxt "title" 139 | msgid "This is my title" 140 | msgstr "" 141 | 142 | #~ msgid "%{ nComputed } book" 143 | #~ msgid_plural "%{ nComputed } books" 144 | #~ msgstr[0] "%{ nComputed } libbra" 145 | #~ msgstr[1] "%{ nComputed } libri" 146 | -------------------------------------------------------------------------------- /dev/language/messages.pot: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Content-Type: text/plain; charset=UTF-8\n" 4 | 5 | #: dev/components/DemoPlural.vue:18 6 | msgid "%{ countForUntranslated } item. This is left untranslated on purpose." 7 | msgid_plural "%{ countForUntranslated } items. This is left untranslated on purpose." 8 | msgstr[0] "" 9 | msgstr[1] "" 10 | 11 | #: dev/components/DemoPlural.vue:12 12 | msgid "%{ n } book" 13 | msgid_plural "%{ n } books" 14 | msgstr[0] "" 15 | msgstr[1] "" 16 | 17 | #: dev/components/DemoAlert.vue:35 18 | msgid "%{ n } car" 19 | msgid_plural "%{ n } cars" 20 | msgstr[0] "" 21 | msgstr[1] "" 22 | 23 | #: dev/components/DemoDirective.vue:15 24 | msgid "%{ count } apple" 25 | msgid_plural "%{ count } apples" 26 | msgstr[0] "" 27 | msgstr[1] "" 28 | 29 | #: dev/components/DemoDirective.vue:4 30 | msgid "A random number: %{ random }" 31 | msgstr "" 32 | 33 | #: dev/components/DemoMultilines.vue:3 34 | msgid "Forgotten your password? Enter your \"email address\" below, and we'll email instructions for setting a new one." 35 | msgstr "" 36 | 37 | #. use jsExtractorOpts in gettext.config.js to extract custom keywords 38 | #: dev/components/DemoAlert.vue:24 39 | msgid "Good bye!" 40 | msgstr "" 41 | 42 | #: dev/components/DemoCustomTags.vue:3 43 | msgid "Headline 1" 44 | msgstr "" 45 | 46 | #: dev/components/DemoCustomTags.vue:4 47 | msgid "Headline 2" 48 | msgstr "" 49 | 50 | #: dev/components/DemoCustomTags.vue:5 51 | msgid "Headline 3" 52 | msgstr "" 53 | 54 | #: dev/components/DemoCustomTags.vue:6 55 | msgid "Headline 4" 56 | msgstr "" 57 | 58 | #: dev/components/DemoDirective.vue:9 59 | msgid "Hello %{ name }" 60 | msgstr "" 61 | 62 | #: dev/components/DemoTemplate.vue:11 63 | msgid "hover here and see the title" 64 | msgstr "" 65 | 66 | #: dev/components/DemoPlural.vue:4 67 | msgid "In English, '0' (zero) is always plural." 68 | msgstr "" 69 | 70 | #: dev/components/DemoTemplate.vue:7 71 | msgid "One apple" 72 | msgid_plural "%{n} apples" 73 | msgstr[0] "" 74 | msgstr[1] "" 75 | 76 | #: dev/components/DemoCustomTags.vue:7 77 | msgid "Paragraph" 78 | msgstr "" 79 | 80 | #: dev/components/LanguageSelect.vue:4 81 | msgid "Select your language:" 82 | msgstr "" 83 | 84 | #: dev/components/DemoIf.vue:14 85 | #: dev/components/DemoIf.vue:15 86 | #: dev/components/DemoIf.vue:16 87 | msgid "This is %{ obj.name }" 88 | msgstr "" 89 | 90 | #: dev/components/DemoTemplate.vue:4 91 | msgid "use `__` as a alias of gettext" 92 | msgstr "" 93 | 94 | #: dev/components/DemoTemplate.vue:6 95 | msgid "use `_n` as a alias of ngettext" 96 | msgstr "" 97 | 98 | #: dev/components/DemoTemplate.vue:10 99 | msgid "use `_x` as a alias of pgettext" 100 | msgstr "" 101 | 102 | #: dev/components/DemoTemplate.vue:14 103 | msgid "use `_xn` as a alias of npgettext" 104 | msgstr "" 105 | 106 | #: dev/components/DemoIf.vue:5 107 | msgid "Welcome %{ name }" 108 | msgstr "" 109 | 110 | #: dev/components/DemoTemplate.vue:15 111 | msgctxt "list-item" 112 | msgid "one message" 113 | msgid_plural "%{n} messages" 114 | msgstr[0] "" 115 | msgstr[1] "" 116 | 117 | #: dev/components/DemoTemplate.vue:9 118 | msgctxt "title" 119 | msgid "This is my title" 120 | msgstr "" 121 | -------------------------------------------------------------------------------- /dev/language/translations.json: -------------------------------------------------------------------------------- 1 | {"en_GB":{"%{ countForUntranslated } item. This is left untranslated on purpose.":["%{ countForUntranslated } item. This is left untranslated on purpose.","%{ countForUntranslated } items. This is left untranslated on purpose."],"%{ n } book":["%{ n } book","%{ n } books"],"%{ nComputed } book":["%{ nComputed } book","%{ nComputed } books"],"%{ count } apple":["%{ count } apple","%{ count } apples"],"A random number: %{ random }":"A random number: %{ random }","Forgotten your password? Enter your \"email address\" below, and we'll email instructions for setting a new one.":"Forgotten your password? Enter your \"email address\" below,\n and we'll email instructions for setting a new one.","Headline 1":"Headline 1","Headline 2":"Headline 2","Headline 3":"Headline 3","Headline 4":"Headline 4","Hello %{ name }":"Hello %{ name }","In English, '0' (zero) is always plural.":"In English, '0' (zero) is always plural.","Paragraph":"Paragraph","Select your language:":"Select your language:","This is %{ obj.name }":"This is %{ obj.name }","Use default singular or plural form when there is no translation. This is left untranslated on purpose.":"Use default singular or plural form when there is no translation. This is left untranslated on purpose.","Welcome %{ name }":"Welcome %{ name }"},"fr_FR":{"%{ n } book":["%{ n } livre","%{ n } livres"],"%{ n } car":["%{ n } voiture","%{ n } voitures"],"%{ nComputed } book":["%{ nComputed } livre","%{ nComputed } livres"],"%{ count } apple":["%{ count } pomme","%{ count } pommes"],"A random number: %{ random }":"Un nombre aléatoire : %{ random }","Forgotten your password? Enter your \"email address\" below, and we'll email instructions for setting a new one.":"Mot de passe perdu ? Saisissez votre \"adresse électronique\" ci-dessous\net nous vous enverrons les instructions pour en créer un nouveau.","Good bye!":"Au revoir !","Headline 1":"Titre 1","Headline 2":"Titre 2","Headline 3":"Titre 3","Headline 4":"Titre 4","Hello %{ name }":"Bonjour %{ name }","In English, '0' (zero) is always plural.":"En anglais, '0' (zero) prend toujours le pluriel.","Paragraph":"Paragraphe","Select your language:":"Sélectionner votre langage","This is %{ obj.name }":"C'est %{ obj.name }","Welcome %{ name }":"Bienvenue %{ name }"},"it_IT":{"%{ n } book":["%{ n } libbra","%{ n } libri"],"%{ n } car":["%{ n } auto","%{ n } auto"],"%{ nComputed } book":["%{ nComputed } libbra","%{ nComputed } libri"],"%{ count } apple":["%{ count } mela","%{ count } mele"],"A random number: %{ random }":"Un numero casuale: %{ random }","Forgotten your password? Enter your \"email address\" below, and we'll email instructions for setting a new one.":"Password dimenticata? Inserisci il tuo \"indirizzo email\" qui\nsotto, e ti invieremo istruzioni per impostarne una nuova.","Good bye!":"Arriverdeci!","Headline 1":"Titolo 1","Headline 2":"Titolo 2","Headline 3":"Titolo 3","Headline 4":"Titolo 4","Hello %{ name }":"Buongiorno %{ name }","In English, '0' (zero) is always plural.":"In inglese, '0' (zero) è sempre al plurale.","Paragraph":"Paragrafo","Select your language:":"Seleziona la tua lingua:","This is %{ obj.name }":"Questo è %{ obj.name }","Welcome %{ name }":"Benvenuto %{ name }"},"zh_CN":{"%{ n } book":"%{ n } 本书","%{ n } car":"%{ n } 辆车","%{ nComputed } book":"%{ nComputed } 本书","%{ count } apple":"%{ count } 个苹果","A random number: %{ random }":"一个随机数: %{ random }","Forgotten your password? Enter your \"email address\" below, and we'll email instructions for setting a new one.":"忘记密码了吗?请在下面输入你的「电子邮件地址」,我们将通过电子邮件发送设置新密码的说明。","Good bye!":"再见","Headline 1":"一级标题","Headline 2":"二级标题","Headline 3":"三级标题","Headline 4":"四级标题","Hello %{ name }":"%{ name } 你好","hover here and see the title":"在此悬浮以查看标题","In English, '0' (zero) is always plural.":"在英语中,0(零)总是复数。","Paragraph":"段落","Select your language:":"请选择语言","This is %{ obj.name }":"这是 %{ obj.name }","use `__` as a alias of gettext":"使用 `__` 作为 gettext 的别名","use `_n` as a alias of ngettext":"使用 `_n` 作为 ngettext 的别名","use `_x` as a alias of pgettext":"使用 `_x` 作为 pgettext 的别名","use `_xn` as a alias of npgettext":"使用 `_xn` 作为 npgettext 的别名","Welcome %{ name }":"欢迎 %{ name }","one message":{"list-item":"%{n} 条消息"},"This is my title":{"title":"这是我的标题"}}} -------------------------------------------------------------------------------- /dev/language/zh_CN/app.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: vue 3-gettext\n" 4 | "Last-Translator: Automatically generated\n" 5 | "Language-Team: none\n" 6 | "Language: zh_CN\n" 7 | "MIME-Version: 1.0\n" 8 | "Content-Type: text/plain; charset=UTF-8\n" 9 | "Content-Transfer-Encoding: 8bit\n" 10 | "Plural-Forms: nplurals=1; plural=0;\n" 11 | 12 | #: dev/components/DemoPlural.vue:18 13 | msgid "%{ countForUntranslated } item. This is left untranslated on purpose." 14 | msgid_plural "" 15 | "%{ countForUntranslated } items. This is left untranslated on purpose." 16 | msgstr[0] "" 17 | 18 | #: dev/components/DemoPlural.vue:12 19 | msgid "%{ n } book" 20 | msgid_plural "%{ n } books" 21 | msgstr[0] "%{ n } 本书" 22 | 23 | #: dev/components/DemoAlert.vue:35 24 | msgid "%{ n } car" 25 | msgid_plural "%{ n } cars" 26 | msgstr[0] "%{ n } 辆车" 27 | 28 | #: dev/components/DemoDirective.vue:15 29 | msgid "%{ count } apple" 30 | msgid_plural "%{ count } apples" 31 | msgstr[0] "%{ count } 个苹果" 32 | 33 | #: dev/components/DemoDirective.vue:4 34 | msgid "A random number: %{ random }" 35 | msgstr "一个随机数: %{ random }" 36 | 37 | #: dev/components/DemoMultilines.vue:3 38 | msgid "" 39 | "Forgotten your password? Enter your \"email address\" below, and we'll email " 40 | "instructions for setting a new one." 41 | msgstr "" 42 | "忘记密码了吗?请在下面输入你的「电子邮件地址」,我们将通过电子邮件发送设置新" 43 | "密码的说明。" 44 | 45 | #. use jsExtractorOpts in gettext.config.js to extract custom keywords 46 | #: dev/components/DemoAlert.vue:24 47 | msgid "Good bye!" 48 | msgstr "再见" 49 | 50 | #: dev/components/DemoCustomTags.vue:3 51 | msgid "Headline 1" 52 | msgstr "一级标题" 53 | 54 | #: dev/components/DemoCustomTags.vue:4 55 | msgid "Headline 2" 56 | msgstr "二级标题" 57 | 58 | #: dev/components/DemoCustomTags.vue:5 59 | msgid "Headline 3" 60 | msgstr "三级标题" 61 | 62 | #: dev/components/DemoCustomTags.vue:6 63 | msgid "Headline 4" 64 | msgstr "四级标题" 65 | 66 | #: dev/components/DemoDirective.vue:9 67 | msgid "Hello %{ name }" 68 | msgstr "%{ name } 你好" 69 | 70 | #: dev/components/DemoTemplate.vue:11 71 | msgid "hover here and see the title" 72 | msgstr "在此悬浮以查看标题" 73 | 74 | #: dev/components/DemoPlural.vue:4 75 | msgid "In English, '0' (zero) is always plural." 76 | msgstr "在英语中,0(零)总是复数。" 77 | 78 | #: dev/components/DemoTemplate.vue:7 79 | msgid "One apple" 80 | msgid_plural "%{n} apples" 81 | msgstr[0] "" 82 | 83 | #: dev/components/DemoCustomTags.vue:7 84 | msgid "Paragraph" 85 | msgstr "段落" 86 | 87 | #: dev/components/LanguageSelect.vue:4 88 | msgid "Select your language:" 89 | msgstr "请选择语言" 90 | 91 | #: dev/components/DemoIf.vue:14 dev/components/DemoIf.vue:15 92 | #: dev/components/DemoIf.vue:16 93 | msgid "This is %{ obj.name }" 94 | msgstr "这是 %{ obj.name }" 95 | 96 | #: dev/components/DemoTemplate.vue:4 97 | msgid "use `__` as a alias of gettext" 98 | msgstr "使用 `__` 作为 gettext 的别名" 99 | 100 | #: dev/components/DemoTemplate.vue:6 101 | msgid "use `_n` as a alias of ngettext" 102 | msgstr "使用 `_n` 作为 ngettext 的别名" 103 | 104 | #: dev/components/DemoTemplate.vue:10 105 | msgid "use `_x` as a alias of pgettext" 106 | msgstr "使用 `_x` 作为 pgettext 的别名" 107 | 108 | #: dev/components/DemoTemplate.vue:14 109 | msgid "use `_xn` as a alias of npgettext" 110 | msgstr "使用 `_xn` 作为 npgettext 的别名" 111 | 112 | #: dev/components/DemoIf.vue:5 113 | msgid "Welcome %{ name }" 114 | msgstr "欢迎 %{ name }" 115 | 116 | #: dev/components/DemoTemplate.vue:15 117 | msgctxt "list-item" 118 | msgid "one message" 119 | msgid_plural "%{n} messages" 120 | msgstr[0] "%{n} 条消息" 121 | 122 | #: dev/components/DemoTemplate.vue:9 123 | msgctxt "title" 124 | msgid "This is my title" 125 | msgstr "这是我的标题" 126 | 127 | #~ msgid "%{ nComputed } book" 128 | #~ msgid_plural "%{ nComputed } books" 129 | #~ msgstr[0] "%{ nComputed } 本书" 130 | -------------------------------------------------------------------------------- /dev/main.ts: -------------------------------------------------------------------------------- 1 | import { createApp } from "vue"; 2 | import App from "./App.vue"; 3 | import { gettext } from "./i18n"; 4 | 5 | const app = createApp(App); 6 | 7 | app.use(gettext); 8 | 9 | app.mount("#app"); 10 | 11 | export default app; 12 | -------------------------------------------------------------------------------- /dev/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "resolveJsonModule": true, 4 | "esModuleInterop": true, 5 | "baseUrl": "./", 6 | "paths": { 7 | "/@gettext/": [ 8 | "../src" 9 | ] 10 | } 11 | }, 12 | "include": [ 13 | "./**/*" 14 | ], 15 | } -------------------------------------------------------------------------------- /dev/variables.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --color-grey: #e5e5e5; 3 | --color-blue: #00aff2; 4 | } 5 | -------------------------------------------------------------------------------- /dev/vite.config.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | import vue from "@vitejs/plugin-vue"; 3 | import { defineConfig } from "vite"; 4 | 5 | export default defineConfig({ 6 | plugins: [vue()], 7 | resolve: { 8 | alias: { 9 | "/@/": path.resolve(__dirname, "./src"), 10 | "/@gettext/": path.resolve(__dirname, "../src"), 11 | }, 12 | }, 13 | }); 14 | -------------------------------------------------------------------------------- /docs/.vuepress/client.ts: -------------------------------------------------------------------------------- 1 | import { defineClientConfig } from "@vuepress/client"; 2 | import Demo from "../../dev/App.vue"; 3 | import { gettext } from "../../dev/i18n"; 4 | 5 | export default defineClientConfig({ 6 | enhance({ app }) { 7 | app.use(gettext); 8 | 9 | app.component("Demo", Demo); 10 | }, 11 | }); 12 | -------------------------------------------------------------------------------- /docs/.vuepress/config.ts: -------------------------------------------------------------------------------- 1 | import { viteBundler } from "@vuepress/bundler-vite"; 2 | import { defaultTheme } from "@vuepress/theme-default"; 3 | import path from "node:path"; 4 | import { defineUserConfig } from "vuepress"; 5 | 6 | export default defineUserConfig({ 7 | base: "/vue3-gettext/", 8 | port: 8080, 9 | lang: "en-US", 10 | title: "Vue 3 Gettext", 11 | description: "Translate your Vue 3 applications with Gettext", 12 | bundler: viteBundler({ 13 | viteOptions: { 14 | resolve: { 15 | alias: { 16 | vue: "vue/dist/vue.esm-bundler.js", 17 | "/@gettext/": path.resolve(__dirname, "../../src"), 18 | }, 19 | }, 20 | }, 21 | }), 22 | locales: { 23 | "/": { 24 | lang: "en-US", 25 | }, 26 | "/zh/": { 27 | lang: "zh-CN", 28 | title: "Vue 3 Gettext", 29 | description: "使用 Gettext 国际化你的 Vue3 应用", 30 | }, 31 | }, 32 | theme: defaultTheme({ 33 | repo: "https://github.com/jshmrtn/vue3-gettext", 34 | navbar: [{ text: "npm", link: "https://npmjs.com/package/vue-haystack" }], 35 | locales: { 36 | "/": { 37 | selectLanguageName: "English", 38 | }, 39 | "/zh/": { 40 | selectLanguageName: "简体中文", 41 | editLinkText: "在 GitHub 上编辑此页", 42 | lastUpdatedText: "上次更新", 43 | contributorsText: "贡献者", 44 | sidebar: [ 45 | { link: "/zh/demo.md", text: "在线演示" }, 46 | { 47 | text: "安装与设置", 48 | link: "/zh/setup.md", 49 | children: [ 50 | { link: "/zh/setup.md", text: "安装步骤" }, 51 | { link: "/zh/extraction.md", text: "自动抽取" }, 52 | { link: "/zh/configuration.md", text: "插件配置" }, 53 | ], 54 | }, 55 | { 56 | text: "使用方法", 57 | link: "/zh/functions.md", 58 | children: [ 59 | { link: "/zh/functions.md", text: "全局属性" }, 60 | { link: "/zh/component.md", text: "组件(已废弃)" }, 61 | { link: "/zh/directive.md", text: "指令(已废弃)" }, 62 | ], 63 | }, 64 | { 65 | text: "翻译文档说明", 66 | link: "/zh/translation.md", 67 | }, 68 | ], 69 | }, 70 | }, 71 | sidebar: [ 72 | { link: "/demo.md", text: "Demo" }, 73 | { 74 | text: "Setup", 75 | link: "/setup.md", 76 | children: [ 77 | { link: "/setup.md", text: "Installation" }, 78 | { link: "/extraction.md", text: "Message extraction" }, 79 | { link: "/configuration.md", text: "Configuration" }, 80 | ], 81 | }, 82 | { 83 | text: "Usage", 84 | link: "/functions.md", 85 | children: [ 86 | { link: "/functions.md", text: "Functions" }, 87 | { link: "/component.md", text: "Component" }, 88 | { link: "/directive.md", text: "Directive" }, 89 | ], 90 | }, 91 | { 92 | text: "Translation", 93 | link: "/translation.md", 94 | }, 95 | ], 96 | }), 97 | }); 98 | -------------------------------------------------------------------------------- /docs/.vuepress/styles/index.scss: -------------------------------------------------------------------------------- 1 | .translated { 2 | border-radius: 0.25rem; 3 | background-color: rgba(241, 245, 17, 0.1); 4 | border: 1px solid rgba(241, 245, 17, 0.5); 5 | } 6 | 7 | .warning { 8 | border-radius: 0.5rem; 9 | padding: 0.5rem; 10 | background-color: #fff3cd; 11 | border: 1px solid #ffecb5; 12 | color: #664d03; 13 | } 14 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | home: true 3 | heroText: Vue 3 Gettext 4 | tagline: Translate your Vue 3 applications with Gettext 5 | actions: 6 | - text: Demo 7 | link: /demo.html 8 | type: primary 9 | - text: Setup 10 | link: /setup.html 11 | type: secondary 12 | - text: Docs 13 | link: /setup.html 14 | type: secondary 15 | footer: MIT Licensed | Copyright © 2020-present JOSHMARTIN GmbH 16 | --- 17 | 18 | # Quick Start 19 | 20 | ```sh 21 | npm i vue3-gettext@next 22 | ``` 23 | 24 | Set up gettext in your `main.ts`/`main.js`: 25 | 26 | ```javascript {main.ts/main.js} 27 | import { createGettext } from "vue3-gettext"; 28 | import { createApp } from "vue"; 29 | import translations from "./src/language/translations.json"; 30 | 31 | const app = createApp(App); 32 | app.use(createGettext({ translations })); 33 | ``` 34 | 35 | Use gettext functions in your application: 36 | 37 | ```jsx 38 | {{ $gettext("Translate me") }} 39 | ``` 40 | 41 | Add scripts to your `package.json`: 42 | 43 | ```json { package.json } 44 | "scripts": { 45 | ... 46 | "gettext:extract": "vue-gettext-extract", 47 | "gettext:compile": "vue-gettext-compile", 48 | } 49 | ``` 50 | 51 | `npm run gettext:extract` extracts translation keys from your code and creates `.po` files to translate. 52 | 53 | `npm run gettext:compile` compiles the translated messages from the `.po` files to a `.json` to be used in your application. 54 | -------------------------------------------------------------------------------- /docs/component.md: -------------------------------------------------------------------------------- 1 | # `` 2 | 3 |
4 | Deprecated 5 |

The <translate> component and v-translate directive have been deprecated, use the functions instead.

6 |

Since Vue 3, extracting messages from within components is awkward and error-prone as well as cause issues with server-side rendering.

7 | To make the transition easier, they will keep working until a future major release. 8 |
9 | 10 | ## Usage 11 | 12 | 13 | ```vue 14 | Hello 15 | ``` 16 | 17 | 18 | `` renders a `` by default, use `tag` to override. 19 | 20 | 21 | ```vue 22 | Hello 23 | ``` 24 | 25 | 26 | ### Parameters 27 | 28 | If the parameter should change dynamically, use the `:translate-params` prop (or use the `v-translate` directive). 29 | 30 | 31 | ```vue 32 | Hello %{ name }! 33 | ``` 34 | 35 | 36 | ### Pluralization 37 | 38 | 39 | ```vue 40 | 45 | %{ amount } car 46 | 47 | ``` 48 | 49 | 50 | ## Props 51 | 52 | | Prop | Description | Type | Default | 53 | | ----------------- | --------------------------------------------------- | ------ | ------- | 54 | | tag | HTML tag that contains the message | string | span | 55 | | translate-n | Determines what plural form to apply to the message | number | null | 56 | | translate-plural | Pluralized message | string | null | 57 | | translate-context | Gettext translation context | string | null | 58 | | translate-params | Parameters to interpolate messages | Object | null | 59 | | translate-comment | Comment for the message id | string | null | 60 | -------------------------------------------------------------------------------- /docs/configuration.md: -------------------------------------------------------------------------------- 1 | # Configuration 2 | 3 | Once you have extracted your messages and compiled a `.json` file, you are ready to set up the gettext plugin in your `main.ts`/`main.js`: 4 | 5 | ```ts 6 | import { createGettext } from "vue3-gettext"; 7 | import translations from "./language/translations.json"; 8 | 9 | const gettext = createGettext({ 10 | availableLanguages: { 11 | en: "English", 12 | de: "Deutsch", 13 | }, 14 | defaultLanguage: "en", 15 | translations: translations, 16 | }); 17 | 18 | const app = createApp(App); 19 | app.use(gettext); 20 | ``` 21 | 22 | All the available options can be found in the `GetTextOptions` type, these are the default values: 23 | 24 | ```ts 25 | { 26 | availableLanguages: { en: "English" }, 27 | defaultLanguage: "en", 28 | mutedLanguages: [], 29 | silent: false, 30 | translations: {}, 31 | setGlobalProperties: true, 32 | globalProperties: { // custom global properties name 33 | language: ['$language'], // the plugin instance 34 | gettext: ['$gettext'], // ['$gettext', '__'] 35 | pgettext: ['$pgettext'], // ['$pgettext', '_n'] 36 | ngettext: ['$ngettext'], // ['$ngettext','_x'] 37 | npgettext: ['$npgettext'], // ['$npgettext', '_nx'] 38 | interpolate: ['$gettextInterpolate'],// deprecated 39 | }, 40 | provideDirective: true, 41 | provideComponent: true, 42 | } 43 | ``` 44 | 45 | ## Gotchas 46 | 47 | ### Using gettext functions outside of components 48 | 49 | If you need to have plain typescript/javascript files that must access gettext, you may simple move and export gettext from a separate file: 50 | 51 | `gettext.ts` 52 | 53 | ```ts 54 | export default createGettext({ 55 | ... 56 | }); 57 | ``` 58 | 59 | Then import and use the functions: 60 | 61 | ```ts 62 | import gettext from "./gettext"; 63 | 64 | const { $gettext } = gettext; 65 | 66 | const myTest = $gettext("My translation message"); 67 | ``` 68 | -------------------------------------------------------------------------------- /docs/demo.md: -------------------------------------------------------------------------------- 1 | # Demo 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /docs/directive.md: -------------------------------------------------------------------------------- 1 | # `v-translate` 2 | 3 |
4 | Deprecated 5 |

The <translate> component and v-translate directive have been deprecated, use the functions instead.

6 |

Since Vue 3, extracting messages from within components is awkward and error-prone as well as cause issues with server-side rendering.

7 | To make the transition easier, they will keep working until a future major release. 8 |
9 | 10 | ## Basic usage 11 | 12 | ```vue 13 | Hello 14 | ``` 15 | 16 | ### Parameters 17 | 18 | Variables for message interpolation must be passed as value to the `v-translate` directive directly. 19 | 20 | 21 | ```vue 22 |

Hello %{ name }!

23 | ``` 24 | 25 | 26 | ### Pluralization 27 | 28 | 29 | ```vue 30 |

35 | %{ amount } car 36 |

37 | ``` 38 | 39 | 40 | ## Attributes 41 | 42 | | Prop | Description | Type | Default | 43 | | ----------------- | -------------------------------------------------------------------------------------------- | ------- | ------- | 44 | | v-translate | **Required**. You can optionally provide an object with parameters for message interpolation | object | null | 45 | | translate-n | Determines what plural form to apply to the message | number | null | 46 | | translate-plural | Pluralized message | string | null | 47 | | translate-context | Gettext translation context | string | null | 48 | | translate-comment | Comment for the message id | string | null | 49 | | render-html | Will disable HTML escaping and render it directly | boolean | false | 50 | -------------------------------------------------------------------------------- /docs/extraction.md: -------------------------------------------------------------------------------- 1 | # Message extraction 2 | 3 | To extract all the messages that you want translated from your application code, a bit of setup is required. 4 | 5 | ## Scripts 6 | 7 | First, add scripts to your `package.json`: 8 | 9 | ```json { package.json } 10 | "scripts": { 11 | ... 12 | "gettext:extract": "vue-gettext-extract", 13 | "gettext:compile": "vue-gettext-compile", 14 | } 15 | ``` 16 | 17 | `npm run gettext:extract` extracts messages from your code and creates `.po` files. 18 | 19 | `npm run gettext:compile` compiles the translated messages from the `.po` files to a `.json` to be used in your application. 20 | 21 | Using these scripts is _theoretically_ optional if you have other means of extraction or may even want to write message files yourself. 22 | 23 | ## Configuration 24 | 25 | Before running the scripts, create a file `gettext.config.js` in your application root. This is a configuration _only_ for the scripts above. A minimal configuration may look like this: 26 | 27 | ```js 28 | module.exports = { 29 | output: { 30 | locales: ["en", "de"], 31 | }, 32 | }; 33 | ``` 34 | 35 | You can also use a `gettext.config.mjs` file with the Ecmascript module format: 36 | 37 | ```js 38 | export default { 39 | output: { 40 | locales: ["en", "de"], 41 | }, 42 | } 43 | ``` 44 | 45 | Here are all the available configuration options and their defaults: 46 | 47 | ```js 48 | module.exports = { 49 | input: { 50 | path: "./src", // only files in this directory are considered for extraction 51 | include: ["**/*.js", "**/*.ts", "**/*.vue"], // glob patterns to select files for extraction 52 | exclude: [], // glob patterns to exclude files from extraction 53 | jsExtractorOpts:[ // custom extractor keyword. default empty. 54 | { 55 | keyword: "__", // only extractor default keyword such as $gettext,use keyword to custom 56 | options: { // see https://github.com/lukasgeiter/gettext-extractor 57 | content: { 58 | replaceNewLines: "\n", 59 | }, 60 | arguments: { 61 | text: 0, 62 | }, 63 | }, 64 | }, 65 | { 66 | keyword: "_n", // $ngettext 67 | options: { 68 | content: { 69 | replaceNewLines: "\n", 70 | }, 71 | arguments: { 72 | text: 0, 73 | textPlural: 1, 74 | }, 75 | }, 76 | }, 77 | ], 78 | compileTemplate: false, // do not compile