mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-07 06:09:42 +00:00
Created [i18n] How to translate i2pd web console to your language (markdown)
75
[i18n]-How-to-translate-i2pd-web-console-to-your-language.md
Normal file
75
[i18n]-How-to-translate-i2pd-web-console-to-your-language.md
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
Translation support for web console was added, so you can translate it to your language.
|
||||||
|
|
||||||
|
For translation take [Russian translation](https://github.com/PurpleI2P/i2pd/blob/openssl/i18n/Russian.cpp) code, make copy with your language name as file name, and update strings in it.
|
||||||
|
|
||||||
|
In that example will be used Turkmen as target language
|
||||||
|
|
||||||
|
# Translation steps
|
||||||
|
|
||||||
|
1. Update translation namespace to your language:
|
||||||
|
```diff
|
||||||
|
namespace i18n
|
||||||
|
{
|
||||||
|
-namespace russian // language
|
||||||
|
+namespace turkmen // language
|
||||||
|
{
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Update plural form function using information from https://localization-guide.readthedocs.io/en/latest/l10n/pluralforms.html:
|
||||||
|
```diff
|
||||||
|
// See for language plural forms here:
|
||||||
|
// https://localization-guide.readthedocs.io/en/latest/l10n/pluralforms.html
|
||||||
|
static int plural (int n) {
|
||||||
|
- return n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;
|
||||||
|
+ return n != 1 ? 1 : 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Update translatable strings and numeric strings in plural form:
|
||||||
|
```diff
|
||||||
|
static std::map<std::string, std::string> strings
|
||||||
|
{
|
||||||
|
// HTTP Proxy
|
||||||
|
- {"Proxy error", "Ошибка прокси"},
|
||||||
|
- {"Proxy info", "Информация прокси"},
|
||||||
|
- {"Proxy error: Host not found", "Ошибка прокси: Адрес не найден"},
|
||||||
|
+ {"Proxy error", "Proksi ýalňyşlygy"},
|
||||||
|
+ {"Proxy info", "Proksi maglumat"},
|
||||||
|
+ {"Proxy error: Host not found", "Proksi ýalňyşlygy: Host tapylmady"},
|
||||||
|
...
|
||||||
|
static std::map<std::string, std::vector<std::string>> plurals
|
||||||
|
{
|
||||||
|
// ShowUptime
|
||||||
|
- {"days", {"день", "дня", "дней"}},
|
||||||
|
- {"hours", {"час", "часа", "часов"}},
|
||||||
|
+ {"days", {"gün", "gün"}},
|
||||||
|
+ {"hours", {"sagat", "sagat"}},
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Add language namespace in i18n header file [`I18N_langs.h`](https://github.com/PurpleI2P/i2pd/blob/e412b17f709af249ffa20a08cb111090631e8d0e/i18n/I18N_langs.h#L61):
|
||||||
|
```diff
|
||||||
|
namespace english { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
||||||
|
namespace russian { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
||||||
|
+ namespace turkmen { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
and in [`I18N.h`](https://github.com/PurpleI2P/i2pd/blob/e412b17f709af249ffa20a08cb111090631e8d0e/i18n/I18N.h#L22-L23):
|
||||||
|
```diff
|
||||||
|
inline void SetLanguage(const std::string &lang)
|
||||||
|
{
|
||||||
|
if (!lang.compare("russian"))
|
||||||
|
i2p::context.SetLanguage (i2p::i18n::russian::GetLocale());
|
||||||
|
+ else if (!lang.compare("turkmen"))
|
||||||
|
+ i2p::context.SetLanguage (i2p::i18n::turkmen::GetLocale());
|
||||||
|
```
|
||||||
|
|
||||||
|
5. Add commentary about new added language to [`i2pd.conf`](https://github.com/PurpleI2P/i2pd/blob/e412b17f709af249ffa20a08cb111090631e8d0e/contrib/i2pd.conf#L107):
|
||||||
|
```diff
|
||||||
|
-## Currently supported english (default), russian and ukrainian languages
|
||||||
|
+## Currently supported english (default), russian, turkmen and ukrainian languages
|
||||||
|
# lang = english
|
||||||
|
```
|
||||||
|
|
||||||
|
6. Make pull request with changes
|
||||||
Reference in New Issue
Block a user