Files

> > CS2D > Lua Scripts > [OR] Diversity 1.2
Files overviewCS2D overviewLua Scripts overview

English [OR] Diversity 1.2 >

13 comments3 kb, 506 Downloads

old [OR] Diversity 1.2

Dousea
User Off Offline

▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

> Versions
• Version 1.1 - 05.19.2016 >

• Version 1.2 - 06.16.2016 >


∗ Overview
Diversity is a simple tool to control languages. You want to use multiple languages in your script? Use Diversity!

flame Example
1
2
Welcome, $1!
Enjoy your stay!
1
2
Selamat datang, $1!
Bersenang-senanglah!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
local language = require("sys/lua/diversity")
local currentlanguage = {}

for id = 1, 32 do
	currentlanguage[id] = "English"
end

function serveractionhook(id, action)
	if (action == 1) then
		currentlanguage[id] = currentlanguage[id] == "English" and "Indonesian" or "English"
	end
end

function joinhook(id)
	msg2(id, language(currentlanguage[id], 1, player(id, "name")) .. "@C")
	msg2(id, language(currentlanguage[id], 2) .. "@C")
end

addhook("serveraction", "serveractionhook")
addhook("join", "joinhook")

spam Documentation
This is the section where you can learn how to add your own languages and how to use them.

First, let's take a look of the configurations.cfg file. There're several configurations you can set on your liking. First is loaddirectory configuration, is to set the load directory of your languages. Second is officiallanguages configuration, is to set the official languages of your script, so if these official languages aren't available, there will be an error.

Second, is to understand how to add your own languages. You need to insert your languages inside the loaddirectory configuration directory. Your language files must be in text (*.txt) form. A new line is to end a line of your languages' lines, just like the usual. There's a symbol that used to manipulate the strings of the languages, that is '$'. '$' is used for subtitution. Example of a complete language:
1
2
You've been attacked by $1!
Are you sure to replace $1 with $2?

Third, is to understand how to use the languages. You need to understand how to use functions, that's it. First load Diversity to your script by requiring it, and save it to a variable:
1
local language = require("sys/lua/diversity")
Then to use the languages, use the used variable for Diversity with format of:
1
<variable>(<language-name>, <language-line>,[ <line-subtitution-1>, <line-subtitution-2>, ...])
1
2
3
language("English", 1) -- You've been attacked by $1
language("English", 1, "Ortimh") -- You've been attacked by Ortimh
language("English", 2, "null", "nil") -- Are you sure to replace null with nil?

illegal Rules
• You are allowed to use this script in your server.
• You are allowed to edit this script for your server.
• You are not allowed to copy any part of this script without permission.
• You are not allowed to say this script is yours.

off-topic Installation
1. Download the file and then extract it anywhere in your CS2D directory.
2. Connect your script with this script using require.
3. Use Diversity to control your languages!

▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
edited 9×, last 16.06.16 08:39:25 am
Approved by GeoB99

Download Download

3 kb, 506 Downloads

Comments

13 comments
To the start Previous 1 Next To the start

Log in!

You need to log in to be able to write comments!Log in

old

Gaios
Reviewer Off Offline

I will use it soon

Error in your example. Change your code to this below:
1
2
3
4
function joinhook(id)
     msg2(id, language(currentlanguage[id], 1, player(id, "name")) .. "@C")
     msg2(id, language(currentlanguage[id], 2) .. "@C")
end
I like it!
edited 1×, last 13.06.16 05:39:04 pm

old

Dousea
User Off Offline

@user MikuAuahDark: That works? Well I might change that. Anyway the checking is not that performance-heavy.

old

MikuAuahDark
User Off Offline

Looks like you're checking if the CS2D version is less than 1.0.0.2 right? Here are single-line CS2D version checking.

assert((_CS2DVERSION or "1.0.0.0") < "1.0.0.2","Requires CS2D v1.0.0.2")


It's possible to check the version that way instead of converting everything to number which can gives little performance overhead.
I like it!

old

Dousea
User Off Offline

@user MikuAuahDark: Yeah, I've been thinking about that. Will do as soon as I can.

old

MikuAuahDark
User Off Offline

It's looks useful for Citylife script which I rewrite from stratch due to messy code.

However, it might be useful if there's function which allows the values to be passed and then used as $1, $2, ...

Example:
format_language("English", 2, "Test", "Null") -- Are you sure to replace Test with Null?
I like it!

old

Dousea
User Off Offline

@user Yates: Sure. It will work just the way you want it to.

old

Yates
Reviewer Off Offline

If this works the way I want it to, I may use it in Y.A.T.E.S if allowed?
I like it!

old

EngiN33R
Moderator Off Offline

I always enjoy seeing i18n-related projects. Definitely a useful tool.
I like it!

old

GeoB99
Moderator Off Offline

Truly impressive! Was thinking about an idea similarly to this several days ago although I couldn't come up with a working, flexible step algorithm to show up different languages. Definitely a honest like should be given.
I like it!

old

Waldin
User Off Offline

looks nice 4 my scripts, gj
I like it!

old

Dousea
User Off Offline

@user _Yank: Calling directly from the table is simpler than calling from a function, well in terms of typing and performance.

old

_Yank
User Off Offline

You could do a function to simplify the querying process so it could be used like, for example,
1
dictionary(currentlanguage[id], 1, player(id, "name"))

But yeah, good job!
I like it!

old

Rygna
User Off Offline

Great Job!, its can be Useful with Custom Language on Roleplay.
I like it!
To the start Previous 1 Next To the start