Thanks for understanding that English is used as a shared language in this repository. Maintainers do not use machine translation to avoid miscommunication due to error in translation. If description of issue / PR are written in non-English languages, those may be closed.
It is of course fine to use non-English language, when you open a PR to translate documents and communicates with other users in same language.
-
The
master
branch is the latest stable version release. All development should be done in dedicated branches. -
Checkout a topic branch from the relevant branch, e.g.
master
, and merge back against that branch. -
Work in the
src
folder and DO NOT checkindist
in the commits. -
If adding new feature:
- Add accompanying test case.
- Provide convincing reason to add this feature. Ideally you should open a suggestion issue first and have it greenlighted before working on it.
-
If fixing a bug:
- Provide detailed description of the bug in the PR. Live demo preferred.
- Add appropriate test coverage if applicable.
-
It's OK to have multiple small commits as you work on the PR - we will let GitHub automatically squash it before merging.
-
Make sure
npm test
passes. (see development setup)
- Fork the repository from intlify/vue-i18n !
- Create your topic branch from
master
:git branch my-new-topic origin/master
- Add codes and pass tests !
- Commit your changes:
git commit -am 'Add some topic'
- Push to the branch:
git push origin my-new-topic
- Submit a pull request to
master
branch ofintlify/vue-i18n
repository !
You will need Node.js version 16+, and PNPM.
We also recommend installing ni to help switching between repos using different package managers. ni
also provides the handy nr
command which running npm scripts easier.
After cloning the repo, run:
$ pnpm i # install the dependencies of the project
A high level overview of tools used:
- TypeScript as the development language
- Rollup for bundling
- Vitest for unit testing
- Playwright for e2e testing
- ESLint for code linting
- Prettier for code formatting
The build
script builds all public packages (packages without private: true
in their package.json
).
Packages to build can be specified with fuzzy matching:
# build message-compiler only
pnpm build -- message-compiler
# build all packages
pnpm build -- --all
By default, each package will be built in multiple distribution formats as specified in the buildOptions.formats
field in its package.json
. These can be overwritten via the -f
flag. The following formats are supported:
-
global
-
esm-bundler
- Leaves prod/dev branches with
process.env.NODE_ENV
guards (to be replaced by bundler) - Does not ship a minified build (to be done together with the rest of the code after bundling)
- For use with bundlers like
webpack
,rollup
andparcel
.
- Leaves prod/dev branches with
-
esm-browser
- For usage via native ES modules imports (in browser via
<script type="module">
, or via Node.js native ES modules support in the future) - Inlines all dependencies - i.e. it's a single ES module with no imports from other files
- This means you must import everything from this file and this file only to ensure you are getting the same instance of code.
- Hard-coded prod/dev branches, and the prod build is pre-minified (you will have to use different paths/aliases for dev/prod)
- For usage via native ES modules imports (in browser via
-
cjs
- For use in Node.js server-side rendering via
require()
. - The dev/prod files are pre-built, but are dynamically required based on
process.env.NODE_ENV
inindex.js
, which is the default entry when you dorequire('vue-i18n')
.
- For use in Node.js server-side rendering via
For example, to build compiler
with the global build only:
pnpm build -- message-compiler -f global
Multiple formats can be specified as a comma-separated list:
pnpm build -- message-compiler -f esm-browser,cjs
Use the --sourcemap
or -s
flag to build with source maps. Note this will make the build much slower.
The --types
or -t
flag will generate type declarations during the build and in addition:
- Roll the declarations into a single
.d.ts
file for each package; - Generate an API report in
<projectRoot>/temp/<packageName>.api.md
. This report contains potential warnings emitted by api-extractor. - Generate an API model json in
<projectRoot>/temp/<packageName>.api.json
. This file can be used to generate a Markdown version of the exported APIs.
The dev
script bundles a target package (default: vue-i18n
) in a specified format (default: global
) in dev mode and watches for changes. This is useful when you want to load up a build in an HTML page for quick debugging:
$ pnpm dev
> rollup v1.19.4
> bundles packages/vue-i18n/src/index.ts → packages/vue-i18n/dist/vue-i18n.global.js...
-
The
dev
script also supports fuzzy match for the target package, but will only match the first package matched. -
The
dev
script supports specifying build format via the-f
flag just like thebuild
script. -
The
dev
script also supports the-s
flag for generating source maps, but it will make rebuilds slower.
The test
script simply calls the jest
binary, so all Jest CLI Options can be used. Some examples:
# run all tests
$ pnpm test
# run tests in watch mode
$ pnpm test -- --watch
# run all tests under the runtime-core package
$ pnpm test -- compiler
# run tests in a specific file
$ pnpm test -- fileName
# run a specific test in a specific file
$ pnpm test -- fileName -t 'test name'
This repository employs a monorepo setup which hosts a number of associated packages under the packages
directory:
flowchart TD
message-compiler
core-base
core
vue-i18n-core
petite-vue-i18n
vue-i18n
subgraph Framework Agnostice Packages
core-base --> message-compiler
core --> core-base
end
subgraph Vue Layer Packages
vue-i18n-core --> core-base
vue-i18n --> core-base
vue-i18n --> vue-i18n-core
petite-vue-i18n --> core-base
petite-vue-i18n --> vue-i18n-core
end
message-compiler
: The intlify message format compiler.core-base
: The inlitfy core logic implementation.core
: The intlify core "full build" which includes both the runtime AND the compiler.vue-i18n-core
: The vue-i18n core implementation.petite-vue-i18n
: The vue-i18n "small build" which includes both the runtime AND the compiler.vue-i18n
: The vue-i18n "full build" which includes both the runtime AND the compiler.
There are some caveats to these packages:
- The modules
vue-i18n
andvue-i18n-core
, the core logic ofpetite-vue-i18n
, should be imported with relative paths. - Similarly for
core
, modules ofcore-base
, which is the core logic implemented, should be imported with relative paths.
The packages can import each other directly using their package names. Note that when importing a package, the name listed in its package.json
should be used. Most of the time the @intlify/
prefix is needed:
import { baseCompile } from '@intlify/compiler'
This is made possible via several configurations:
- For TypeScript,
compilerOptions.path
intsconfig.json
- For plain Node.js, they are linked using PNPM Workspaces.
Unit tests are collocated with directories named test
. Consult the Jest docs and existing test cases for how to write new test specs. Here are some additional guidelines:
Use the minimal API needed for a test case. For example, if a test can be written without involving the reactivity system ra component, it should be written so. This limits the test's exposure to changes in unrelated parts and makes it more stable.
As a pure community-driven project without major corporate backing, we also welcome financial contributions via GitHub Sponsors and Patreon
Funds donated via GitHub Sponsors and Patreon go to support kazuya kawaguchi full-time work on Intlify.
Thank you to all the people who have already contributed to Intlify project and my OSS work !