English [OR] Diversity 1.2 icon

13 comments
14.05.16 06:58:17 pm
like 8 like it!
3 kb, 59 Downloads
Ortimh
User
Offline Off
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

> 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
Code:
1
2
Welcome, $1!
Enjoy your stay!

Code:
1
2
Selamat datang, $1!
Bersenang-senanglah!

Code:
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:
Code:
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:
Code:
1
local language = require("sys/lua/diversity")

Then to use the languages, use the used variable for Diversity with format of:
Code:
1
<variable>(<language-name>, <language-line>,[ <line-subtitution-1>, <line-subtitution-2>, ...])
Code:
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
ok This file has been reviewed and approved by Fraizeraust (14.05.16 07:25:20 pm)

Comments

13 comments
Goto Page
To the start Previous 1 Next To the start

Log in!

You need to log in to be able to write comments!Log in
13.06.16 05:13:06 pm
like I like it!
Up
Gaios
Security Supporter
Offline Off
I will use it soon

Error in your example. Change your code to this below:
Code:
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
edited 1×, last 13.06.16 05:39:04 pm
24.05.16 05:11:09 pm
Up
Ortimh
User
Offline Off
@user MikuAuahDark: That works? Well I might change that. Anyway the checking is not that performance-heavy.
24.05.16 05:06:33 pm
like I like it!
Up
MikuAuahDark
User
Offline Off
Looks like you're checking if the CS2D version is less than 1.0.0.2 right? Here are single-line CS2D version checking.

Code:
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.
19.05.16 06:53:24 am
Up
Ortimh
User
Offline Off
@user MikuAuahDark: Yeah, I've been thinking about that. Will do as soon as I can.
19.05.16 06:44:21 am
like I like it!
Up
MikuAuahDark
User
Offline Off
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:
Code:
format_language("English", 2, "Test", "Null") -- Are you sure to replace Test with Null?
16.05.16 11:55:31 pm
Up
Ortimh
User
Offline Off
@user Yates: Sure. It will work just the way you want it to.
16.05.16 07:14:32 pm
like I like it!
Up
Yates
Reviewer
Offline Off
If this works the way I want it to, I may use it in Y.A.T.E.S if allowed?
16.05.16 06:38:25 pm
like I like it!
Up
EngiN33R
Moderator
Offline Off
I always enjoy seeing i18n-related projects. Definitely a useful tool.
16.05.16 06:44:24 am
like I like it!
Up
Fraizeraust
Moderator
Offline Off
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.
15.05.16 06:26:11 pm
like I like it!
Up
Waldin
User
Offline Off
looks nice 4 my scripts, gj
15.05.16 11:51:06 am
Up
Ortimh
User
Offline Off
@user _Yank: Calling directly from the table is simpler than calling from a function, well in terms of typing and performance.
15.05.16 10:59:54 am
like I like it!
Up
_Yank
User
Offline Off
You could do a function to simplify the querying process so it could be used like, for example,
Code:
1
dictionary(currentlanguage[id], 1, player(id, "name"))


But yeah, good job!
15.05.16 03:49:48 am
like I like it!
Up
Rygna
User
Offline Off
Great Job!, its can be Useful with Custom Language on Roleplay.
To the start Previous 1 Next To the start