-
Notifications
You must be signed in to change notification settings - Fork 639
Description
Right now, localizations are stored like this:
edit/src/bin/edit/localization.rs
Lines 244 to 257 in c13b8ab
| // 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.