Skip to content

Allow more languages to be maintained by the project #165

@lhecker

Description

@lhecker

Right now, localizations are stored like this:

// FileNew
[
/* en */ "New File…",
/* de */ "Neue Datei…",
/* es */ "Nuevo archivo…",
/* fr */ "Nouveau fichier…",
/* it */ "Nuovo file…",
/* ja */ "新規ファイル…",
/* ko */ "새 파일…",
/* pt_br */ "Novo arquivo…",
/* ru */ "Новый файл…",
/* zh_hans */ "新建文件…",
/* zh_hant */ "新增檔案…",
],

In other words, it's a matrix where the outer index is the string ID and the inner index is the language ID. Due to this it's impossible toggle languages on and off. What we need is ideally something like this:

const S_LANG_LUT: [[&str; _]; _] = generate_lut();

const generate_lut() -> [[&str; _]; _] {
   let mut lut = [[""; _]; _];

    #[cfg(feature = "lang-en")]
    lut[NewFile][en] = "New File…";
    #[cfg(feature = "lang-de")]
    lut[NewFile][de] = "Neue Datei…";
    #[cfg(feature = "lang-es")]
    lut[NewFile][es] = "Nuevo archivo…";
    #[cfg(feature = "lang-fr")]
    lut[NewFile][fr] = "Nouveau fichier…";
    #[cfg(feature = "lang-it")]
    lut[NewFile][it] = "Nuovo file…";
    #[cfg(feature = "lang-ja")]
    lut[NewFile][ja] = "新規ファイル…";
    #[cfg(feature = "lang-ko")]
    lut[NewFile][ko] = "새 파일…";
    #[cfg(feature = "lang-pt_br")]
    lut[NewFile][pt_br] = "Novo arquivo…";
    #[cfg(feature = "lang-ru")]
    lut[NewFile][ru] = "Новый файл…";
    #[cfg(feature = "lang-zh_hans")]
    lut[NewFile][zh_hans] = "新建文件…";
    #[cfg(feature = "lang-zh_hant")]
    lut[NewFile][zh_hant] = "新增檔案…";

   lut
}

Perhaps this can be abstracted away with a macro?

This then allows us to add more languages and toggle them on and off depending on the needs. Someone who wants the smallest possible editor for instance may disable everything except for lang-en. This is absolutely not a problem yet: The current localizations are only about 10kB large. Rather, I think that this may otherwise grow into an issue long-term, given that there's a lot of languages out there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-taskSmaller tasks. Requires work in the 100s of LOC (usually).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions