Jump to content

[REL] Translations Resource v1.0


Skurken

Recommended Posts

Posted (edited)

This is a very small script that allows you to easily implement multilinguality in your scripts and interfaces.

You edit translations.xml to add more translated strings, as this example shows:

<translations> 
    <language name='English'> 
        <string id='HELLO' text='Hello'/> 
    </language> 
    <language name='Catalan'> 
        <string id='HELLO' text='Hola'/> 
    </language> 
</translations> 

Then in your script you can do:

local catalan = exports.translations:getTranslationTable('Catalan') 
  
print (catalan.HELLO) -- Outputs Hola 
  
--OR 
  
local langs = exports.translations.getTranslationTable() 
  
print (langs.Catalan.HELLO) 

Community

GitHub

Edited by Guest
Posted

I get the point i am saying that is easyer / less work with direct table. That copy the whole xml line's ower and ower.

local multi={} 
  
multi[en]={"hello"} 
multi[..]={"HELLO"} 
  
guiCreateBlabla(multi[..][1]) 

Posted

My server's one is based on tables, for an example, the button would be the exact language, I use the same method bandi recommended, so this is an example. Tables are more reliable and quicker than XML files:

local translations = {} 
translations['English'] = { 
['not well'] = 'not well`', 
['Hello'] = 'Hello' 
} 
translations['Spanish'] = { 
['not well'] = 'Mal', 
['Hello'] = 'Hola' 
} 
  
-- Main Code 
addEventHandler('onClientResourceStart', resourceRoot, 
function() 
    local englishButton = guiCreateButton(237, 61, 73, 29, "English", false, false) 
    local spanishButton = guiCreateButton(237, 27, 73, 29, "Spanish", false, false) 
     
    helloLabel = guiCreateLabel(242, 189, 146, 21, translations['English']['Hello'], false, false) 
    notWellLabel = guiCreateLabel(242, 168, 146, 21,translations['English']['not well'], false, false) 
     
    addEventHandler('onClientGUIClick', englishButton, buttonHandler) 
    addEventHandler('onClientGUIClick', spanishButton, buttonHandler) 
end 
  
function buttonHandler() 
    local selectedLanguage = guiGetText(source) 
     
    guiSetText(helloLabel, translations[selectedLanguage]['Hello']) 
    guiSetText(helloLabel, translations[selectedLanguage]['notWell']) 
end) 

Posted (edited)

Translations are only loaded once the resource starts, a table is then created and used from that point on. I do believe that managing translations in an xml format is easier than tables.

Edited by Guest
Posted

I don't find anything wrong with using XML. Table is just another way of fetching and organizing data. It might be easier to fetch data from a table, but to be honest XML is easier for translators to understand as most of translators don't have any basic idea of scripting, not insulting anyone, but not everyone is made to be a scripter.

Posted
https://developers.google.com/translate/v2/pricing?hl=nl - I'm sure this API could possibly solve you having to write each word. However, this comes with a price.

Have you even read the pricing? Some of us spend a lot of money on our current servers and we don't really want to blow money on that API. I use a few API's and in the near future I'll be using Google Graph API, but google translate is way to much. Our server/s use about 1.8 tb of data a month and our server's are constantly filled with players.

  • 3 weeks later...
Posted
Don't use XML.

You and everyone else in here's ignorance about XML is hilarious. If it's loaded a single time, XML does not matter. XML will make it far easier for the end user to edit vs using Lua tables. Better yet, it's for a UI. I don't see there being more than maybe 50 lines in the XML. It really isn't that big of a deal.

  • MTA Team
Posted

Well his implementation isn't very good, you do realise that there'd be lots of repetitiveness.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...