• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Acubens Language System Works on [0.3/0.4] [getPlayerLanguage(cid)]

Acubens

Old Penguin
Joined
May 6, 2008
Messages
1,261
Solutions
13
Reaction score
184
Location
Venezuela
Acubens Multi-Language System [LUA & PHP]

Hello otland this is a simple system what i was created for my project is not a big deal but it is very useful for international rpg servers

Step 1) Saving the function in lib/050-functions.lua

Lua:
-- By Acubens 
-- For Otland.net 

function getPlayerLanguage(cid)
    local Lang = db.getResult("SELECT `language` FROM `accounts` WHERE `id` = " .. getPlayerAccountId(cid) .. " LIMIT 1")
        if Lang:getID() ~= LUA_ERROR then
        local langid = Lang:getDataInt("language")
        Lang:free()
        return langid
    end
     return LUA_ERROR
end


Step 2) Creating the column in your database

PHP:
ALTER TABLE  `accounts` ADD  `language` INT( 11 ) NOT NULL DEFAULT  '0'


Step 3) Add constants variables in lib/000-constant.lua



Lua:
ENGLISH = 0
SPANISH = 1
PORTUGUES = 2
-- and etc..

You can define your custom languages with id.


How Works this function?

Example: If you want send Welcome message in the language of the player.

Lua:
function onLogin(cid)

local language = getPlayerLanguage(cid)

	if language == ENGLISH then
		doPlayerSendTextMessage(cid,22, "Welcome adventurer!")
	elseif language == SPANISH then
		doPlayerSendTextMessage(cid,22, "Bienvenido aventurero!")	
	elseif language == PORTUGUES then
		doPlayerSendTextMessage(cid,22, "Bem-vindo aventureiro!")	
	end

return true
end

Register in news Accounts for Gesior Acc You need edit config.php, createaccount.php and OTS_Account.php

in config.php add the language config:

PHP:
//Language System by Acubens
$config['site']['languages'] = array(0 => 'English', 1 => 'Spanish', 2 => 'Portugues'); //and etc..

Under:
PHP:
 <TR><TD width="150"><b>Email status:</b></TD><TD colspan="2"><b><div id="email_check">Please enter your e-mail.</div></b></TD></TR>';

Add:
PHP:
//Language System by Acubens
$main_content .= '<TR><TD width="150"><b>Idioma/Language:</b></TD><TD colspan="2"><b><select name="language">';
foreach($config['site']['languages'] as $language_id => $lang)
{
                    		
	 $main_content .= '<option value="'.$language_id.'">'.$lang.'</option>';
}
Under:

PHP:
$reg_country = trim($_POST['country']);

Add:

PHP:
$reg_language = trim($_POST['language']);

Under:

PHP:
$reg_account->setCustomField("flag", $reg_country);

Add

PHP:
$reg_account->setCustomField("language", $reg_language);


in htdocs/pot/OTS_Account.php after:

PHP:
public function getRLName()
	{
        if( !isset($this->data['rlname']) )
        {
            throw new E_OTS_NotLoaded();
	}

	return $this->data['rlname'];
}
add
PHP:
//Language System by Acubens
public function getPlayerLanguage() {
	
	if( !isset($this->data['language']) ) 
	{
           	 throw new E_OTS_NotLoaded();
        }
	return $this->data['language'];
}


Now you can use too in your web page to show the content in differents languages without make 2 websites or more.

Enjoy, dont forget rep me :)!
 
Last edited:
Updated. added language configuration in config.php and the function in OTS_Account.php.
 
Last edited:
That's hardly worthy of the title of 'system' but hey, to each their own.

Some suggestions. Here is a table of preexisting well known numerical and two letter IDs for i18n/L10n use.
Code:
33  :  English     :  en-us
43  :  Dutch       :  nl-nl
34  :  Spanish     :  es-es
46  :  Portuguese  :  pt-br
45  :  Polish      :  pl   
36  :  French      :  fr-fr
40  :  Italian     :  it-it
44  :  Norwegian   :  no-no
53  :  Swedish     :  sv-se
35  :  Finnish     :  fi

and provide a better example of what could be done.. like dual error messaging
Code:
[COLOR=#ff0000]~/lib/some_locale_lib.lua[/COLOR]
ErrorCanc[33].FishSys_Bait      = "You do not have any worms."       
ErrorCanc[34].FishSys_Bait      = "No tienes gusanos."               
ErrorCanc[43].FishSys_Bait      = "Je hebt geen wormen."             
ErrorText[33].FishSys_Bait      = "Fishing requires bait."           
ErrorText[34].FishSys_Bait      = "Se necesita cebo para pescar."    
ErrorText[43].FishSys_Bait      = "Vissen vereist aas."              

[COLOR=#ff0000]~/some_fishing_script.lua[/COLOR]
    elseif item.itemid ~= DONOR_FISHGEAR and FishConfig.useWorms and getPlayerItemCount(cid, ITEM_WORM) < 1 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ErrorText[PlayerLanguage].FishSys_Bait) ; 
        return doPlayerSendCancel(cid, ErrorCanc[PlayerLanguage].FishSys_Bait) ; 
    end ;
 
This seems so familiar. Wonder when I'll get to work on it again ;)
 
translate all text in servers !
data/lib/001language.lua
Lua:
language = {
	[0] = {
	  HELLOWORLD = "Hello world!"
		},

	[1] = {
		   HELLOWORLD = "!Hola, mundo!"
		},

	[2] = {
		   HELLOWORLD = "Olá, mundo!"
		}
}

eg.:
Lua:
local lang = getPlayerLanguage(cid)
doPlayerSendTextMessage(cid,22, language[lang].HELLOWORLD)
 
First of all excuse my English, my intention is not to make this system a trunk of language libraries with constant messages, I use to do that each time a message is sent has the availability in the selected languages ​​I like things simple, thanks for the suggestions but i dont search that way
 
function onLogin(cid)

local language = getPlayerLanguage(cid)

if language == ENGLISH then
doPlayerSendTextMessage(cid,22, "Welcome adventurer!")
elseif language == SPANISH then
doPlayerSendTextMessage(cid,22, "Bienvenido aventurero!")
elseif language == PORTUGUES then
doPlayerSendTextMessage(cid,22, "Bem-vindo aventureiro!")
end

return true
end
can u say where to add it and so?
 
A library of translated constant strings is the only humane way to treat human translators.

I should have noticed this before. This is a glaring error in judgement, perhaps even an epic journey through a seizure leaving you comatose, then permanently retarded.
ADD `language` INT( 11 )

This is far more suitable. Of course replace 33 with 0 if you use some weird ass crufty jury rigged wannabe shell of an 'i18n system'
ALTER TABLE `accounts` ADD `language` TINYINT( 2 ) NOT NULL DEFAULT '33'
 
Found a error in this line:
Code:
$reg_account->setCustomField("flag", $reg_language);

Should be:
Code:
$reg_account->setCustomField("language", $reg_language);
 
Back
Top