This plugins provides a simply way to look up definitions for language keyed strings in your codebase. It does so by simple key look up in the configured translation files.
This is intended to be used with setups like i18next and accompanying localization/en.json, localization/da.json, etc. files.
To set up the plugin, require the packager and supply a list of language configurations (filePath, keymap) to the setup function like so (example using Lazy):
return {
"magerlinc/i18n.nvim",
require('i18n').setup({
{
filePath = 'path/to/your/translations.json',
keymap = 'your-keymap'
},
{
filePath = 'path/to/your/other-translations.json',
keymap = 'your-other-keymap'
}
})
}For example, if you have a translation file en.json like this:
{
"hello": "Hello",
}And you set up the configuration like this:
require('i18n').setup({
{
filePath = 'path/to/your/en.json',
keymap = '<leader>en'
}
})You can press <leader>en while your cursor is anywhere inside the string "hello" to look it up in the en.json file.
const greeting = t('hello'); // pressing <leader>en while your cursor is in the string will open the en.json file and go to the "hello" keyThis plugin also supports passing a creation script and a keymap to call it:
require('i18n').setup({
{
creationKeymap = "<leader>gl",
creationCmd = "yarn genlabel",
}
})This will allow you to press <leader>gl to run the given shell command, which can fx. run a script which generates the translation entries for you.