From 0630b54193a39853e38b5c60411fecac26cbc5e2 Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+Berry-13@users.noreply.github.com> Date: Tue, 1 Aug 2023 14:14:01 +0200 Subject: [PATCH] docs: add how to add a language (#732) * Create language-contributions.md * Update language-contributions.md * Update README.md * Update mkdocs.yml * Update README.md * Update language-contributions.md * Create languages.md * Update languages.md * Update README.md * Update mkdocs.yml * fix space languages.md fix space at line 61 --- README.md | 3 +- docs/contributions/language-contributions.md | 80 +++++++++++++ docs/install/languages.md | 113 +++++++++++++++++++ mkdocs.yml | 3 +- 4 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 docs/contributions/language-contributions.md create mode 100644 docs/install/languages.md diff --git a/README.md b/README.md index 8432bf6db6..4da7d3708b 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ Keep up with the latest updates by visiting the releases page - [Releases](https * [APIs and Tokens](docs/install/apis_and_tokens.md) * [User Auth System](docs/install/user_auth_system.md) * [Online MongoDB Database](docs/install/mongodb.md) + * [Languages](docs/install/languages.md)
@@ -112,7 +113,7 @@ Keep up with the latest updates by visiting the releases page - [Releases](https
Contributions - + * [Contributor Guidelines](CONTRIBUTING.md) * [Documentation Guidelines](docs/contributions/documentation_guidelines.md) * [Code Standards and Conventions](docs/contributions/coding_conventions.md) diff --git a/docs/contributions/language-contributions.md b/docs/contributions/language-contributions.md new file mode 100644 index 0000000000..cc8c84a6b9 --- /dev/null +++ b/docs/contributions/language-contributions.md @@ -0,0 +1,80 @@ +# How to add a language to LibreChat + +## Minimum Requirements: + +1. Good knowledge of the language (some terms may undergo significant changes during translation) +2. An editor, which can be Notepad or (**recommended**: [VSCode](https://code.visualstudio.com/download)) + +## Language translation + + +1. Fork the LibreChat repository and download it using git clone https://github.com/danny-avila/LibreChat +2. Navigate to the "client\src\localization" folder and open the "Translation.tsx" file +3. At the beginning of the code, add your language below all the others in this format: + +`import Language-name from './languages/** ';` + +For example, let's take English as an example: + +Note: Replace "LanguageName" with the name of your language (capitalized) and "**" with the ISO 3166 Alpha-2 code of your country (the initial of the nation). +If you don't know the ISO 3166 code for your language, check it [here](https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes) and also use it with an initial capital) + +4. Further down in the code, add the following + +`if (langCode === '**') return Language-name;` + +Replace "**" with the ISO 3166 Alpha-2 code of your language (in lowercase). Here's an example: `if (langCode === 'en') return English;`) + +7.Go into the "languages" folder and create a file named as follows: **.tsx + +For example: En.tsx + +9. Copy all the content from En.tsx into your file and modify it as follows: + +``` +// your-language-name phrases + +export default { + com_ui_examples: 'Examples', + // Add more translations here +``` + +Rename only the part after the colon ":" to the corresponding translation in your language. For example: + +``` +// my-language phrases + +export default { + com_ui_examples: 'WORD_THAT_I_TRANSLATE_IN_TO_MY_LANGUAGE', + // Add more translations here +}; +``` + +⚠️DO NOT CHANGE com_... ⚠️ + +10. To add your language to the menu, open the file "client\src\components\Nav\SettingsTabs\General.tsx" and add your language to the "LangSelector" variable in the following way: + +``` +export const LangSelector = ({ + //other code + + //other languages... + + + + ); +}; +``` + +where ** is the ISO 3166 Alpha-2 code and "com_nav_lang_your-language-name" stands for the name in your language (for example com_nav_lang_english or com_nav_lang_italian) +The only line of code to add is: + +`` + +11. Commit your changes using git add *, git commit -m "Language translation: your-language translation" and git push. +12. Open your repository in a browser and click on "Contribute" + +![image](https://github.com/Berry-13/LibreChat/assets/81851188/ab91cf4b-1830-4419-9d0c-68fcb2fd5f5e) + +14. Answer all the questions, and in the "Type of Change" section, add `- [x] Translation support` +15. Create a pull request 🎉 diff --git a/docs/install/languages.md b/docs/install/languages.md new file mode 100644 index 0000000000..d3d0744647 --- /dev/null +++ b/docs/install/languages.md @@ -0,0 +1,113 @@ +# Languages 🌍 + +## Default language + +1. Open this file "client\src\store\language.js" +2. modify the "default" in the lang variable with your ISO 3166 Alpha-2 code : + +for example from english as default + +``` +import { atom } from 'recoil'; + +const lang = atom({ + key: 'lang', + default: 'en', +}); + +export default { lang }; +``` + +to italian as dafult + +``` +import { atom } from 'recoil'; + +const lang = atom({ + key: 'lang', + default: 'it', +}); + +export default { lang }; +``` + +# How to add a translation to LibreChat + +### Minimum Requirements: + +1. Good knowledge of the language (some terms may undergo significant changes during translation) +2. An editor, which can be Notepad or (**recommended**: [VSCode](https://code.visualstudio.com/download)) + +### Language translation + + +1. Fork the LibreChat repository and download it using git clone https://github.com/danny-avila/LibreChat +2. Navigate to the "client\src\localization" folder and open the "Translation.tsx" file +3. At the beginning of the code, add your language below all the others in this format: + +`import Language-name from './languages/** ';` + +For example, let's take English as an example: + +Note: Replace "LanguageName" with the name of your language (capitalized) and "**" with the ISO 3166 Alpha-2 code of your country (the initial of the nation). +If you don't know the ISO 3166 code for your language, check it [here](https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes) and also use it with an initial capital) + +4. Further down in the code, add the following + +`if (langCode === '**') return Language-name;` + +Replace "**" with the ISO 3166 Alpha-2 code of your language (in lowercase). Here's an example: `if (langCode === 'en') return English;`) + +7. Go into the "languages" folder and create a file named as follows: **.tsx + +For example: En.tsx + +9. Copy all the content from En.tsx into your file and modify it as follows: + +``` +// your-language-name phrases + +export default { + com_ui_examples: 'Examples', + // Add more translations here +``` + +Rename only the part after the colon ":" to the corresponding translation in your language. For example: + +``` +// my-language phrases + +export default { + com_ui_examples: 'WORD_THAT_I_TRANSLATE_IN_TO_MY_LANGUAGE', + // Add more translations here +}; +``` + +⚠️DO NOT CHANGE com_... ⚠️ + +10. To add your language to the menu, open the file "client\src\components\Nav\SettingsTabs\General.tsx" and add your language to the "LangSelector" variable in the following way: + +``` +export const LangSelector = ({ + //other code + + //other languages... + + + + ); +}; +``` + +where ** is the ISO 3166 Alpha-2 code and "com_nav_lang_your-language-name" stands for the name in your language (for example com_nav_lang_english or com_nav_lang_italian) +The only line of code to add is: + +`` + +11. Commit your changes using git add *, git commit -m "Language translation: your-language translation" and git push. +12. Open your repository in a browser and click on "Contribute" + +![image](https://github.com/Berry-13/LibreChat/assets/81851188/ab91cf4b-1830-4419-9d0c-68fcb2fd5f5e) + +14. Answer all the questions, and in the "Type of Change" section, add `- [x] Translation support` +15. Create a pull request 🎉 diff --git a/mkdocs.yml b/mkdocs.yml index ac186c0828..c8cf66bcee 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -91,6 +91,7 @@ nav: - APIs and Tokens: 'install/apis_and_tokens.md' - User Auth System: 'install/user_auth_system.md' - Online MongoDB Database: 'install/mongodb.md' + - Languages: 'install/languages.md' - Features: - Plugins: - Introduction: 'features/plugins/introduction.md' @@ -111,7 +112,7 @@ nav: - Contributions: - Documentation Guidelines: 'contributions/documentation_guidelines.md' - Code Standards and Conventions: 'contributions/coding_conventions.md' - - Testing: 'contributions/testing.md' + - Testing: 'contributions/testing.md' extra: social: