Skip to content

Locales API

All of this comes from bs_core/shared/sh_locale.lua. How to set up a resource for translation is on Locales. This page is the reference.

Languages: en, pt, de, pl, tr, es, fr, it, ru. Missing keys fall back to en, then to the key itself.

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

Each locales/<lang>.lua returns a flat table:

return {
['shop.title'] = 'Trader',
['shop.bought'] = 'You bought {item} for ${price}',
}

Placeholders are {name}. An unknown placeholder is left as it is, so typos show up instead of disappearing.

FunctionSideWhat it does
L(key, vars)clientText in the local player’s language
L(key, vars)serverText in the server default language
L(src, key, vars)serverText in that player’s language
Lp(src, key, vars)serverSame as above, always takes a source
BSLocale.T(lang, key, vars)bothText in a language you name
BSLocale.Lang()bothLocal player’s language (client) or the default (server)
BSLocale.LangOf(src)bothA player’s language, falls back to the default
BSLocale.Default()bothServer default (GlobalState.bs_defaultLang, else en)
BSLocale.IsValid(lang)bothIs this one of the nine codes
BSLocale.Dict(lang)bothThe whole table with en underneath, for NUI
BSLocale.OnChange(fn)clientfn(lang) runs when the language changes
BSLocale.Set(lang)clientAsk bs_core to change the player’s language
BSLocale.Languages, BSLocale.NativebothThe code list and the native names

Server export: exports.bs_core:GetLanguage(src).

Always pass the player’s source on the server when the text goes to one player. L('key') without a source uses the server default, which is wrong for a notification.

TriggerClientEvent('bs:ui:notify', src, { type = 'success', message = L(src, 'shop.bought', { item = label, price = 50 }) })
  • Player choice: state bag bs_lang on the player.
  • Server default: GlobalState.bs_defaultLang (F1 Global.defaultLanguage, or the bs_defaultLanguage convar).
  • Saved per account in bs_users.language.
  • Changing it fires the server event bs_core:setLanguage.

If the resource has a ui_page, the locale script answers the bs_i18n NUI callback with { lang, dict } and pushes the new table when the language changes. Load the helper and mark up your HTML:

<script src="nui://bs_ui/html/js/i18n.js"></script>
<span data-i18n="ui.level">LEVEL</span>

In JS: t('key', vars) and BSI18n.onChange(fn). Details on Locales.