Locale Class
The localization system is built around theLocale class defined in shared/locale.lua.
Creating a Locale Instance
With Fallback Language
Translation Files
Qbox Core includes 35+ pre-built language files in thelocales/ directory:
- ar.json (Arabic)
- bg.json (Bulgarian)
- cn.json (Chinese)
- cs.json (Czech)
- da.json (Danish)
- de.json (German)
- en.json (English)
- es.json (Spanish)
- fi.json (Finnish)
- fr.json (French)
- it.json (Italian)
- ja.json (Japanese)
- nl.json (Dutch)
- no.json (Norwegian)
- pl.json (Polish)
- pt.json (Portuguese)
- pt-br.json (Brazilian Portuguese)
- ru.json (Russian)
- sv.json (Swedish)
- tr.json (Turkish)
- vn.json (Vietnamese)
- zh-tw.json (Traditional Chinese)
- …and more!
Translation File Structure
Translation files use nested JSON structure:Using Translations
Basic Translation
Use thet() method to translate a key:
Variable Substitution
Pass a table of substitutions as the second parameter:%{key} and are replaced with tostring(value) (shared/locale.lua:26).
Multiple Substitutions
Locale Methods
extend()
Add new translations to an existing locale:has()
Check if a translation key exists:clear()
Remove all translations:replace()
Replace all translations with a new set:delete()
Remove specific translation keys:locale()
Get or set the current locale identifier:Fallback System
When a translation key is missing:- If
warnOnMissingis true, a warning is printed (shared/locale.lua:107) - If a fallback locale is configured, it’s checked for the key (shared/locale.lua:109)
- If still not found, the key itself is returned (shared/locale.lua:112)
Adding a New Language
Step 1: Create Translation File
Create a new JSON file in thelocales/ directory:
Step 2: Load Translation File
Load the translation file in your resource:Step 3: Use in Your Code
Best Practices
Organize by Category
Group related translations together:Use Descriptive Keys
Make keys self-documenting:Keep Fallback Updated
Always maintain English (or your primary language) translations:Avoid Hardcoded Text
Don’t use hardcoded strings:Example: Multi-Language Resource
Here’s a complete example of a resource with language support:Available Translations in Qbox Core
Qbox Core provides translations for:- Error messages (player not online, wrong format, no access, etc.)
- Success messages (teleported, character deleted, etc.)
- Info messages (paycheck received, job info, duty status, etc.)
- Command help text (all admin commands)
- Character creation UI (first name, last name, nationality, etc.)
- Queue system messages
- Multicharacter UI
locales/en.json for the complete list of available translation keys.