Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internationalization #1505

Open
AndreM222 opened this issue Nov 17, 2024 · 0 comments
Open

Internationalization #1505

AndreM222 opened this issue Nov 17, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@AndreM222
Copy link

AndreM222 commented Nov 17, 2024

First of all great job on developing this plugin.

Feauture

I will like for their to either be a way for me to change the name of titles like references, code actions, etc. so I can add my translations.

Or if this plugin had translations in it it will be great.

Reason

I am currently working on adding internationalization in my own setup , most so I can practice Japanese and not bother other people who might want it in english.

My Approach

I am getting the texts from plugins to exchange them with text that will be translated depending the vim language set.

To get the language set I am using a variable build in which Is

vim.v.lang

Once I get the language it changes the values depending on the languages available and translations.
For me I used a function that when text goes inside It tries to look for an available translation. if it doesnt have then it returns default string.

-- Current Language
local lang = string.sub(vim.v.lang, 1, 2)
-- Translations
local file = io.open(vim.fn.stdpath('config').."/lua/andrem222/lang/"..lang..".json", "rb")
-- Decoded translations
local jsonFile

-- Check if translation available to decode
if file then
    jsonFile = vim.json.decode(file:read("*a"))

    file:close()
end

--- This function returns the translation if available of text in the parameter
--- @param description string Description to translate
--- @return any
function Msgstr(description)
    if not jsonFile then return description end
    if not jsonFile[description] or jsonFile[description]["msgstr"] == '' then return description end

    return jsonFile[description]["msgstr"]
end

NVim Approach

They instead used a cmakelist to get translations and exchange them using gettext.
This one might be better but I am still not knowledgable about that and I'm trying to learn it now to see how to make it work.

https://github.com/neovim/neovim/blob/master/src/nvim/po/CMakeLists.txt

@AndreM222 AndreM222 added the enhancement New feature or request label Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant