metin2united
Sign in to follow this  
BalooUA

Multi-language System

17 posts in this topic

Hey Everyone,
 
since i'm new here, i want to share my Multi-Language System with you as small "contribution" to this community.
 
Many private servers still don't have a proper language-system and i thought it might be a good idea to start sharing stuff with you instead of keeping it only for my server.
 
So let's start :)
 
I've written a quest to select your language and called her: changelanguage.quest
 

quest changelanguage begin
    state start begin
		when login begin
			set_state(change_lang)
      	end
	end

	state change_lang begin
		when letter begin
			send_letter(t('locale.changelanguage.letter'))
		end

	when button or info begin
		local s = 0
		local subset = 1
		while s == 0 or (subset == 1 and s == 6) or (subset == 2 and s == 12) or (subset == 3 and s == 19) or (subset == 4 and s == 22) do
			if s == 0 or (s == 12 and subset == 2) then
				say(t('locale.changelanguage.welcome') .. " " .. pc.get_name() .. " " .. t('locale.changelanguage.msg'))
				subset = 1
				s = select(t('locale.changelanguage.select', 1), t('locale.changelanguage.select', 6), t('locale.changelanguage.select', 3), t('locale.changelanguage.select', 4), t('locale.changelanguage.select', 5), t('locale.main.next'), t('locale.main.cancel'))
			end
			if (s == 6 and subset == 1) or (s == 19 and subset == 3) then
				say(t('locale.changelanguage.welcome') .. " " .. pc.get_name() .. " " .. t('locale.changelanguage.msg'))
				subset = 2
				s = select(t('locale.changelanguage.select', 2), t('locale.changelanguage.select', 7), t('locale.changelanguage.select', 8), t('locale.changelanguage.select', 9), t('locale.changelanguage.select', 14), t('locale.main.next'), t('locale.main.back')) + 5
			end
			if (s == 11 and subset == 2) or (s == 22 and subset == 4) then
				say(t('locale.changelanguage.welcome') .. " " .. pc.get_name() .. " " .. t('locale.changelanguage.msg'))
				subset = 3
				s = select(t('locale.changelanguage.select', 13), t('locale.changelanguage.select', 10), t('locale.changelanguage.select', 20), t('locale.changelanguage.select', 21), t('locale.changelanguage.select', 22), t('locale.main.next'), t('locale.main.back')) + 12
			end
			if s == 18 and subset == 3 then
				say(t('locale.changelanguage.welcome') .. " " .. pc.get_name() .. " " .. t('locale.changelanguage.msg'))
				subset = 4
				s = select(t('locale.changelanguage.select', 23), t('locale.changelanguage.select', 24), t('locale.main.back'), t('locale.main.cancel')) + 19
			end


		end
			if s == 1 then
				set_lang(1)
				say(t('locale.changelanguage.info'))
			elseif s == 2 then
				set_lang(6)
				say(t('locale.changelanguage.info'))
			elseif s == 3 then
				set_lang(3)
				say(t('locale.changelanguage.info'))
			elseif s == 4 then
				set_lang(4)
				say(t('locale.changelanguage.info'))
			elseif s == 5 then
				set_lang(5)
				say(t('locale.changelanguage.info'))

----------------- SUB_SET 2 -------------------------------
			elseif s == 6 then
				set_lang(2)
				say(t('locale.changelanguage.info'))
			elseif s == 7 and subset == 2 then
				set_lang(7)
				say(t('locale.changelanguage.info'))
			elseif s == 8 and subset == 2 then
				set_lang(8)
				say(t('locale.changelanguage.info'))
			elseif s == 9 and subset == 2 then
				set_lang(9)
				say(t('locale.changelanguage.info'))
			elseif s == 10 and subset == 2 then
				set_lang(14)
				say(t('locale.changelanguage.info'))
			elseif s == 14 and subset == 3 then
				set_lang(10)
				say(t('locale.changelanguage.info'))
			elseif s == 13 and subset == 3 then
				set_lang(13)
				say(t('locale.changelanguage.info'))
			elseif s == 15 and subset == 3 then
				set_lang(20)
				say(t('locale.changelanguage.info'))
			elseif s == 16 and subset == 3 then
				set_lang(21)
				say(t('locale.changelanguage.info'))
			elseif s == 17 and subset == 3 then
				set_lang(22)
				say(t('locale.changelanguage.info'))
			elseif s == 20 and subset == 4 then
				set_lang(23)
				say(t('locale.changelanguage.info'))
			elseif s == 21 and subset == 4 then
				set_lang(24)
				say(t('locale.changelanguage.info'))

			end

		end
	end
end

 
As you can see, it contains many different languages, that's why i left the quest complete and didn't clean it up so you can have a better understanding how it works.
 
The quest translation, we've added to our locale.lua.
 
Here a small variable example for the above posted quest, changelanguage.quest:
 

----- changelanguage.quest -----
locale.changelanguage= {}
locale.changelanguage.select = "English"
locale.changelanguage.welcome = "Welcome" 
locale.changelanguage.msg = ",[ENTER]Please select your language![ENTER]"
locale.changelanguage.letter = "Change Language"
locale.changelanguage.info = "You have successfully changed your language![ENTER]"
-------------------------

and in case you want to add more languages, simple add a small syntax like "_de" ( german) which would look like that:

----- changelanguage.quest -----
locale.changelanguage.select_de = "Deutsch"
locale.changelanguage.welcome_de = "Willkommen" 
locale.changelanguage.msg_de = ",[ENTER]Bitte wähle deine Sprache![ENTER]"
locale.changelanguage.letter_de = "Sprache Ändern"
locale.changelanguage.info_de = "Du hast erfolgreich deine Sprache geändert![ENTER]"
-------------------------

 
of course it won't work without the actual function which will be added to: questlib.lua
 

function set_lang(arg)
	local name = string.gsub(pc.get_name(), "[.*](.*)", "%1")
	pc.setf('changelanguage', 'lang_' .. name, arg)
end

and

function t(varname, l)
	local name = string.gsub(pc.get_name(), "[.*](.*)", "%1")
	local line = 0

	line = pc.getf('changelanguage', 'lang_' .. name)

	if not l then 
		l = line
	end

	local lang_suffix = ''

	if l == 1 or l == 0 then
		lang_suffix = ''    -- English (Default)
	elseif l == 2 then
		lang_suffix = '_it' -- Italian
	elseif l == 3 then
		lang_suffix = '_de' -- German
	elseif l == 4 then
		lang_suffix = '_bg' -- Bulgarian
	elseif l == 5 then
		lang_suffix = '_et' -- Estonian
	elseif l == 6 then
		lang_suffix = '_ro' -- Romanian
	elseif l == 7 then
		lang_suffix = '_hr' -- Croatian
	elseif l == 8 then
		lang_suffix = '_cz' -- Czech
	elseif l == 9 then
		lang_suffix = '_pt' -- Portuguese
	elseif l == 10 then
		lang_suffix = '_fr' -- French
	elseif l == 13 then
		lang_suffix = '_lt' -- Lithuanian
	elseif l == 14 then
		lang_suffix = '_hu' -- Hungarian
	elseif l == 20 then
		lang_suffix = '_gr' -- Greek
	elseif l == 21 then
		lang_suffix = '_nl' -- Dutch
	elseif l == 22 then
		lang_suffix = '_pl' -- Polish
	elseif l == 23 then
		lang_suffix = '_se' -- Swedish
	elseif l == 24 then
		lang_suffix = '_mk' -- Macedonian
	end

	s = assert(loadstring( 'return ' ..  varname .. lang_suffix ))
	if not s() or s() == '' then
		s = assert(loadstring( 'return ' ..  varname ))
	end
	if not s() then return "" end
	return(s())
end

And please check if you've set_lang in your quest_functions.

 

 

The function inside your quest will be used like that. For example in "say
 

say("I <3 Metin2Dev")

would be replaced with

say(t('locale.questname.lovemetin2dev'))

I've created the variables based on their quest name and the part where it's used inside the quest to give it more sense and it will make it easier to read later, ones you've 5k+ lines in your locale :P
 

 
I hope you like it and i looking forward to work with and for you guys :)
 
Cheers,
BalooUA

  • Like 8

Share this post


Link to post
Share on other sites
quest changelanguage begin
	state start begin
		when login begin
			set_state(change_lang)
		end
	end

	state change_lang begin
		when letter begin
			send_letter(t('locale.changelanguage.letter'))
		end

		when button or info begin
			local s = 0
			local subset = 1
			local slct_tab = {1,6,3,4,5,2,7,8,9,14,10,13,20,21,22,23,24}
			while s == 0 or (subset == 1 and s == 6) or (subset == 2 and s == 12) or (subset == 3 and s == 19) or (subset == 4 and s == 22) do
				if s == 0 or (s == 12 and subset == 2) then
					say(t('locale.changelanguage.welcome') .. " " .. pc.get_name() .. " " .. t('locale.changelanguage.msg'))
					subset = 1
					s = select(t('locale.changelanguage.select', 1), t('locale.changelanguage.select', 6), t('locale.changelanguage.select', 3), t('locale.changelanguage.select', 4), t('locale.changelanguage.select', 5), t('locale.main.next'), t('locale.main.cancel'))
				end
				if (s == 6 and subset == 1) or (s == 19 and subset == 3) then
					say(t('locale.changelanguage.welcome') .. " " .. pc.get_name() .. " " .. t('locale.changelanguage.msg'))
					subset = 2
					s = select(t('locale.changelanguage.select', 2), t('locale.changelanguage.select', 7), t('locale.changelanguage.select', 8), t('locale.changelanguage.select', 9), t('locale.changelanguage.select', 14), t('locale.main.next'), t('locale.main.back')) + 5
				end
				if (s == 11 and subset == 2) or (s == 22 and subset == 4) then
					say(t('locale.changelanguage.welcome') .. " " .. pc.get_name() .. " " .. t('locale.changelanguage.msg'))
					subset = 3
					s = select(t('locale.changelanguage.select', 13), t('locale.changelanguage.select', 10), t('locale.changelanguage.select', 20), t('locale.changelanguage.select', 21), t('locale.changelanguage.select', 22), t('locale.main.next'), t('locale.main.back')) + 12
				end
				if s == 18 and subset == 3 then
					say(t('locale.changelanguage.welcome') .. " " .. pc.get_name() .. " " .. t('locale.changelanguage.msg'))
					subset = 4
					s = select(t('locale.changelanguage.select', 23), t('locale.changelanguage.select', 24), t('locale.main.back'), t('locale.main.cancel')) + 19
				end
			end
			set_lang(slct_tab[s])
			say(t('locale.changelanguage.info')
		end
	end
end

Don't know if it works, but it should. you can try it c:

It's shorter

  • Like 1

Share this post


Link to post
Share on other sites

Don't know if it works, but it should. you can try it c:

It's shorter

 

I'll try it later. Wrote this quest 2 years ago and it was working fine. "Never change a running system" :P

 

Having the source, there is a sufficient way better than this.

 

Of course there is but when i made this quest back then, there was no source.

Share this post


Link to post
Share on other sites

function say_withlanguage(langName,txt)
	if(type(txt) != "table") then
		return 0
	end
	if(txt[langName] == nil) then
		return 2
	end
	say(txt[langName])
end

--[[
	
	- How to use to this function in my quest? (If you're use to my multi-language quest, let's go.
	
	local lang = {"en","tr"}
	
	say_withlangauge(lang[pc.get_lang()],locale.blacksmith_dialog1)
	
	result is "If there another language for this text, show language text."
	
	another result is "If there any result for this text, show "2" "
	
	- How to use to this function in my quest? (If you're not use to my multi-langauge quest, let's go.
	
	local lang = {"en","tr"}
	local self = pc.getf("questname",pc.name.."_lang")
	
	
	-- locale.lua
	
	
	locale.blacksmith_dialog1 = {
		["en"] = "text1",
		["tr"] = "text2",
	}
	
	
	say_withlanguage(lang[self],locale.blacksmith_dialog1)
	
	- I hope you're like it.
	
	Kind Regards
	HaveBeen
]]--

Little function.

Thanks share us.

  • Like 1

Share this post


Link to post
Share on other sites

@HaveBeen™, i've just post this 2yo quest because we're working on a better solution, based on language files which we'll load over the client. Anyways i like your function but it's overall view inside the locale.lua might be a bit messy with it, at least for me.

Share this post


Link to post
Share on other sites
On 01/04/2014 at 7:57 PM, HaveBeen™ said:

there are many solution for this system.

 

I just wanna show a solution you :)

 

Kind Regards

HaveBeen

 

Exactly. In my case, I made a new quest function.

Share this post


Link to post
Share on other sites

My error :

u3QlkFx.png

You forgot to put the quest functions, don't forget to put also in the quest_functions file this:

t

#Edit: i wass writing this post and Denic posted and i only noticed after sry for double post.

Share this post


Link to post
Share on other sites

Thank you this tutorial, do you know how make multi language chat? 

Example: when 9003.chat."letter" begin

i tried when 9003.chat.t('translate.lua.say_1') and when 9003.chat.(t('translate.lua.say_1'))  but no works :S

Sorry my bad english

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.