๐ŸŒ BuxarTranslate Localization

File: localization.html
Purpose: Localization guide and adding new languages

๐ŸŒ Supported Interface Languages

๐Ÿ‡บ๐Ÿ‡ธ English en

Default language, full support

๐Ÿ‡ท๐Ÿ‡บ Russian ru

Full interface localization

๐Ÿ‡ฉ๐Ÿ‡ช Deutsch de

German interface language

๐Ÿ‡ช๐Ÿ‡ธ Spanish es

Spanish interface language

๐Ÿ‡ซ๐Ÿ‡ท French fr

French interface language

๐Ÿ‡ฎ๐Ÿ‡น Italian it

Italian interface language

๐Ÿ“ Localization Structure

Localization is organized according to WebExtensions standard in _locales folder:

_locales/ โ”œโ”€โ”€ en/ โ”‚ โ””โ”€โ”€ messages.json # English translations โ”œโ”€โ”€ ru/ โ”‚ โ””โ”€โ”€ messages.json # Russian translations โ”œโ”€โ”€ de/ โ”‚ โ””โ”€โ”€ messages.json # German translations โ”œโ”€โ”€ es/ โ”‚ โ””โ”€โ”€ messages.json # Spanish translations โ”œโ”€โ”€ it/ โ”‚ โ””โ”€โ”€ messages.json # Italian translations โ””โ”€โ”€ fr/ โ””โ”€โ”€ messages.json # French translations

๐Ÿ“ Translation File Format

Each messages.json file contains object with translation keys:

{ "extensionName": { "message": "BuxarTranslate", "description": "Extension name" }, "extensionDescription": { "message": "Translate selected text in emails with one click", "description": "Extension description" }, "translateTo": { "message": "Translate to $1", "description": "Context menu item" }, "selectTextRightClick": { "message": "Select text โ†’ Right-click โ†’ Translate", "description": "Popup instruction" } }

๐Ÿ”ง Adding New Language

1. Create language folder

Create folder with language code in _locales/ directory

mkdir _locales/ja # for Japanese language
2. Create messages.json file

Create translation file in new folder

touch _locales/ja/messages.json
3. Add translations

Copy structure from English file and translate all values

{ "extensionName": { "message": "BuxarTranslate", "description": "Extension name" }, "translateTo": { "message": "Translate to $1", "description": "Context menu item" } }
4. Update language scanning

Add language code to scanAvailableLanguages() function in popup.js

// In popup.js file const possibleLangs = ['en', 'ru', 'es', 'de', 'fr', 'it', 'ja', 'zh', 'ko']; // Add your language to possibleLangs array
5. Test translation

Install extension and test new language operation

๐Ÿ”„ Dynamic Translation Loading

System dynamically loads translations for selected language:

// Loading translations for specific language async function loadTranslations(lang) { try { const response = await fetch(`_locales/${lang}/messages.json`); if (response.ok) { return await response.json(); } } catch (error) { console.error(`Error loading translations for ${lang}:`, error); } return null; } // Language manager const LanguageManager = { async init() { const storage = await browser.storage.local.get('userLang'); const userLang = storage.userLang || 'auto'; // Determine interface language if (userLang === 'auto') { const uiLang = browser.i18n.getUILanguage(); this.currentLang = uiLang.split('-')[0]; } else { this.currentLang = userLang; } // Load translations this.translations = await loadTranslations(this.currentLang) || {}; } };

๐ŸŽฏ Key Translation Elements

Mandatory translation keys:

Placeholders in translations:

// Example of placeholder usage "translateTo": { "message": "Translate to $1", "description": "Context menu item" } // In code: const menuTitle = browser.i18n.getMessage("translateTo", [targetLangName]);

๐Ÿ” Localization Testing

Automatic Detection

Set userLang: "auto" to test automatic language detection

Manual Selection

Use dropdown in settings to switch between languages

Check All Elements

Make sure all interface elements and messages are translated

Test Placeholders

Check correct replacement of $1, $2 etc. in translations

โš ๏ธ Common Issues

Missing Keys

Solution: Make sure all keys from English version are present in translation

Incorrect Placeholders

Solution: Check correspondence of $1, $2 count in translation and code

File Encoding

Solution: Save JSON files in UTF-8 encoding

Syntax Errors

Solution: Check JSON validity using JSON validator