Skip to content

Languages & translations

The game UI can run in 9 languages: en, pt, de, pl, tr, es, fr, it, ru. Not every string is translated yet, anything missing falls back to English.

  • Each player’s choice is saved per account (bs_users.language, added by migration 030_user_language.sql) and published on the player state bag bs_lang.
  • An empty choice means “follow the server default”. The default comes from F1 Global.defaultLanguage, else the bs_defaultLanguage convar, else en. It’s on GlobalState.bs_defaultLang.
  • Players change it in the inventory Settings tab. That fires bs_core:setLanguage, and every resource updates live, no reconnect.
  • exports.bs_core:GetLanguage(src) gives you a player’s language on the server.

Resources with a locales/ folder so far: bs_admin, bs_bodily, bs_boosters, bs_building, bs_chat, bs_cinecam, bs_core, bs_crafting, bs_drugs, bs_economy, bs_emotes, bs_events, bs_extraction, bs_faction_bases, bs_factions, bs_gadgets, bs_gates, bs_interactions, bs_inventory, bs_jobs, bs_medical, bs_menu, bs_mining, bs_multichar, bs_radial, bs_recycler, bs_scenes, bs_scoreboard, bs_skills, bs_stash, bs_tester, bs_traders, bs_ui, bs_vehicles, bs_vip, bs_weapons, bs_zombies.

The Lua and NUI functions are on Locales API.

shared_script '@bs_core/shared/sh_locale.lua'
files { 'locales/*.lua' }

Each file returns a flat table. {name} is a placeholder.

-- locales/en.lua
return {
['ui.level'] = 'LEVEL',
['msg.picked_up'] = 'You picked up {item}.',
}

Copy en.lua to pt.lua (and so on) and translate the values. Never translate the keys. A missing key falls back to English, then to the key itself, so a half done file is fine.

-- client: the local player's language
local s = L('msg.picked_up', { item = 'Bandage' })
-- server: L(src, key, vars) or Lp(src, key, vars) uses that player's language
TriggerClientEvent('chat:addMessage', src, { args = { L(src, 'msg.picked_up', { item = 'Bandage' }) } })
-- server without a source: the server default
print(L('msg.picked_up', { item = 'Bandage' }))

BSLocale.OnChange(function(lang) ... end) runs on the client when the language changes, for text you built yourself.

If the resource has a ui_page, the locale script sends the merged table to the page. Load the shared helper before your page script:

<script src="nui://bs_ui/html/js/i18n.js"></script>

Then mark up the HTML. The English text in the markup is the fallback:

<span data-i18n="ui.level">LEVEL</span>
<p data-i18n-html="ui.help_html">Press <b>E</b></p>
<input data-i18n-attr="placeholder:ui.search;title:ui.search_tip" placeholder="Search">

In JS use t('key', { name: 'x' }) and BSI18n.onChange(fn) to re-render dynamic text.

  • Keep keys stable and grouped (ui., msg., err.). Changing a key breaks every translation of it.
  • Don’t put game balance text with numbers baked in, use placeholders so the number follows the config.