Système de traduction i18n pour vos packages Onset
La documentation complète du plugin est disponible sur github: i18n.
Exemple d'utilisation
La documentation complète du plugin est disponible sur github: i18n.
Exemple d'utilisation
Less:
local i18n = ImportPackage( 'i18n' ) or error('i18n package is missing (https://github.com/sdieunidou/onset-i18n)!')
i18n.load({ en = { welcome = 'You are not allowed to join this server!', invalid_config = 'Your %{path} has an invalid JSON format. Check it!', connected = 'Welcome %{name}!', }, fr = { welcome = 'Vous n\'êtes pas autorisé à rejoindre ce serveur!', invalid_config = 'Votre fichier %{path} ne respecte pas le format JSON. Corrigez la configuration!', connected = 'Bienvenue %{name}!', }
})
-- i18n.loadFile( 'packages/yourpackage/i18n/en.lua' ) -- load English language file
-- i18n.loadFile( 'packages/yourpackage/i18n/de.lua' ) -- load German language file
-- i18n.loadFile( 'packages/yourpackage/i18n/fr.lua' ) -- load French language file
i18n.setFallbackLocale( "en" )
i18n.setLocale( "en" )
print( i18n.trans( 'welcome') );
print( i18n.trans( 'welcome', { locale = 'en' ) );
print( i18n.trans( 'welcome', { locale = 'fr' ) );
print( i18n.trans( 'invalid_config' ));
print( i18n.trans( 'invalid_config', { path = 'config.json' ) );
print( i18n.trans( 'invalid_config', { path = 'config.json' ) );
function OnPlayerJoin( player ) AddPlayerChat( player, i18n.trans( 'connected', { name = GetPlayerName( player ), locale = GetPlayerLocale( player ) } ) )
end
AddEvent( 'OnPlayerJoin', OnPlayerJoin )