# Internationalization with @pitcher/i18n
@pitcher/i18n
package includes a Vue plugin for translating your applications and a couple of tools to collect keywords for translating through Google Translation API. The package also includes a couple of functions to convert date, time, numbers etc. based on the users locale. Under the hood it has multiple different mechanisms to collect/translate strings and work flawlessly with a Vue application.
Here it is explained how the @pitcher/i18n
plugin works under the hood.
# Gettext helpers
Gettext helpers has 3 main purpose which are:
- collect strings from the application, generate
.po
files and save to desired location - translate strings with the help of Google Translate API
- compile
.po
files to.json
files, save to desired location
Gettext helpers can be runned through command line or with the help of npm scripts.
# i18n store
The store exist for multiple purposes.
- to keep track of available languages
- current language
- language translation messages
- helper functions get current locale when formatting date, time, number etc.
Moreover the values inside store are globally accessible and reactive.
# Vue plugin
The plugin used as a starting point for @pitcher/i18n
package. For plugin to work properly, it needs to be initialized in main.js
.
When you initialize the plugin, it does:
add
$t
,$gettext
,$ngettext
functions towindow
- to be able to call the functions & translate messages in any
.js
file
- to be able to call the functions & translate messages in any
add
$t
,$gettext
,$ngettext
functions to the current Vue instance- to be able to call the functions inside vue templates & components
save plugin options to the store
- to give access to current plugin options globally
# Dependencies
@pitcher/i18n
package has multiple dependencies to work properly.
dependencies: {
"@pitcher/core": "^0.1.7",
"@vue/composition-api": ">= 1.0.0-rc.1",
"vue": ">= 2.6.0"
},
devDependencies: {
"@pitcher/easygettext": "^2.12.5",
"gettext-parser": "^4.0.3"
}
Without these dependencies the plugin will not work properly. There are multiple ways to install @pitcher/i18n
package. To start using it, take a look at Installation section.