DGS Multilingual: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(29 intermediate revisions by the same user not shown)
Line 1: Line 1:


==<span style="color:#000000;text-shadow:0.05em 0.05em 0.2em #00000099;">Description</span>==
==<span style="color:#000000;text-shadow:0.05em 0.05em 0.2em #00000099;">Description</span>==
*1. DGS has a built-in multilingul (multi-languae) system.
*1. DGS has a built-in multilingual (multi-language) system.
*2. Multilingul allows dynamic language changing and prevents non-essential GUI recreating or text reset by code.
*2. multilingual allows dynamic language changing and prevents non-essential GUI recreating or text reset by code.
*3. DGS Multilingul system will specify the structure of **Translation Table** (Dictionary).
*3. DGS multilingual system will specify the structure of '''Translation Table''' (Dictionary).


==<span style="color:#000000;text-shadow:0.05em 0.05em 0.2em #00000099;">Usage</span>==
==<span style="color:#000000;text-shadow:0.05em 0.05em 0.2em #00000099;">Usage 1 (Basic usage)</span>==
===<span style="color:#FF7F00;">Server-Sided</span> G2D script converter (G2DSC)===
*0. Don't forget to '''import DGS Head''' or use "'''export.dgs:'''".
Command: g2d [-Option] [Arguments]
*1. A '''Translation Table''' (Dictionary) should be specified:
{| class="wikitable" style="width: 800px; text-align: center; table-layout: fixed;"
<syntaxhighlight lang="lua">
|-
Dict = {
!Options
TestText1="Welcome To DGS",
!Arguments
}
!Comment
</syntaxhighlight>
|-
 
| -add
*2. And, send the dictionary into DGS:
|Resource Name
<syntaxhighlight lang="lua">
|Retain selections and select other resources (-m :Pattern Match)
dgsSetTranslationTable("testDict",Dict) --Name,Dictionary.
|-
</syntaxhighlight>
| -c
 
|
*3. Now, DGS knows that dictionary, we need to tell DGS we want to use it:
|Clear selections
<syntaxhighlight lang="lua">
|-
dgsSetAttachTranslation("testDict") --This is global setting to one resource
| -h
</syntaxhighlight>
|
 
|G2D Help
*3. Create a label:
|-
<syntaxhighlight lang="lua">
| -rm
label = dgsCreateLabel (0.51, 0.54, 0.16, 0.14, {"TestText"}, true )
|Resource Name
</syntaxhighlight>
|Remove specific selected resources from list  (-m :Pattern Match)
 
|-
==<span style="color:#000000;text-shadow:0.05em 0.05em 0.2em #00000099;">Usage 2 (Basic usage)</span>==
| -l
*0. Don't forget to '''import DGS Head''' or use "'''export.dgs:'''".
|
*1. A '''Translation Table''' (Dictionary) should be specified:
|List all selected resources
<syntaxhighlight lang="lua">
|-
Dict = {
| -e
TestText1="Welcome To DGS",
|
}
|Start to convert (execute)
</syntaxhighlight>
|-
 
| -q
*2. And, send the dictionary into DGS:
|
<syntaxhighlight lang="lua">
|Stop converting process
dgsSetTranslationTable("testDict",Dict) --Name,Dictionary.
|-
</syntaxhighlight>
|}
 
'''Example'''<br>
*3. Now, DGS knows that dictionary, we can create a label and attach its text to the dictionary:
These command is used in MTA Server console.
<syntaxhighlight lang="lua">
label = dgsCreateLabel (0.51, 0.54, 0.16, 0.14, {"TestText"}, true )
dgsAttachToTranslation(label,"testDict") --Only attach one element to the dictionary.
</syntaxhighlight>
Or you can also do:
<syntaxhighlight lang="lua">
label = dgsCreateLabel (0.51, 0.54, 0.16, 0.14, "", true )
dgsAttachToTranslation(label,"testDict") --Only attach one element to the dictionary.
dgsSetText(label,{"TestText"})
</syntaxhighlight>
 
==<span style="color:#000000;text-shadow:0.05em 0.05em 0.2em #00000099;">Usage 3 (With parameters)</span>==
*0. Don't forget to '''import DGS Head''' or use "'''export.dgs:'''".
*1. A '''Translation Table''' (Dictionary) should be specified. And here we have an extra '''%rep%''' that takes the place of '''parameter''':
<syntaxhighlight lang="lua">
Dict = {
TestText1="Welcome To %rep%",
TestText2="Welcome To %rep% %rep%",
}
</syntaxhighlight>
 
*2. And, send the dictionary into DGS:
<syntaxhighlight lang="lua">
dgsSetTranslationTable("testDict",Dict) --Name,Dictionary.
</syntaxhighlight>
 
*3. Now, DGS knows that dictionary, tell DGS we want to use it:
<syntaxhighlight lang="lua">
dgsSetAttachTranslation("testDict")
</syntaxhighlight>
 
*4. Create a label, pass '''"DGS"''' as the argument
<syntaxhighlight lang="lua">
label1 = dgsCreateLabel (0.51, 0.54, 0.16, 0.14, {"TestText1","DGS"}, true )
label2 = dgsCreateLabel (0.51, 0.64, 0.16, 0.14, {"TestText2","DGS",":D"}, true )  -- 2 parameters.
label3 = dgsCreateLabel (0.51, 0.74, 0.16, 0.14, {"TestText2","DGS"}, true )  -- the rest unused '''%rep%''' will be deleted.
</syntaxhighlight>
 
==<span style="color:#000000;text-shadow:0.05em 0.05em 0.2em #00000099;">Usage 4 (High Level Translation)</span>==
*0. Don't forget to '''import DGS Head''' or use "'''export.dgs:'''".
*1. A '''Translation Table''' (Dictionary) should be specified. And DGS parameter support 2nd level translation:
<syntaxhighlight lang="lua">
Dict = {
TestText="Welcome To %rep%. Have a good time %rep%",
Smile=":)",
}
</syntaxhighlight>


Basic:
*2. And, send the dictionary into DGS:
<syntaxhighlight>
<syntaxhighlight lang="lua">
g2d -add resA
dgsSetTranslationTable("testDict",Dict) --Name,Dictionary.
g2d -e
</syntaxhighlight>
</syntaxhighlight>


Advanced Pattern Mode:
*3. Now, DGS knows that dictionary, tell DGS we want to use it:
<syntaxhighlight>
<syntaxhighlight lang="lua">
g2d -add .A -m
dgsSetAttachTranslation("testDict")
g2d -e
</syntaxhighlight>
 
*4. Create a label, and use 2nd level translation:
<syntaxhighlight lang="lua">
label = dgsCreateLabel (0.51, 0.54, 0.16, 0.14, {"TestText","DGS", {"Smile"}}, true )
</syntaxhighlight>
or more
<syntaxhighlight lang="lua">
label = dgsCreateLabel (0.51, 0.54, 0.16, 0.14, {"TestText","DGS", {"TestText",{"TestText","Smile","Smile"},"Smile"}}, true )
</syntaxhighlight>
</syntaxhighlight>


Output files are stored in '''dgs/G2DOutput/'''
==<span style="color:#000000;text-shadow:0.05em 0.05em 0.2em #00000099;">Usage 5 (Conditional Translation)</span>==
<br>
*0. Don't forget to '''import DGS Head''' or use "'''export.dgs:'''".
<br>
*1. A '''Translation Table''' (Dictionary) should be specified. And the translation item should be a table includes ''condition''s and ''result''s.
<syntaxhighlight lang="lua">
testDict = {
exampleTranslation = {
"health == 'Superman'",    "You are a superman",
"find({0}, health)",              "Your health is 0",
"health <= 40",                  "Your health is low",
"health <= 60",                  "Your health is medium",
"health <= 80",                  "Your health is high",
"Your health is $health",
}
}
</syntaxhighlight>


===<span style="color:#FF0000;">Client-Sided</span> G2D Hooker (G2D Hooker)===
*2. The table seems to be hard to understand. But actually, you can understand it like this:
See detail [[dgsG2DLoadHooker]]
<syntaxhighlight lang="lua">
if health == 'Superman' then          --condition 1
return "You are a superman"      --result 1
elseif find({0}, health) then              --condition 2
return "Your health is 0"              --result 2
elseif health <= 40 then                  --condition 3
return "Your health is low"          --result 3
elseif health <= 60 then                  --condition 4
return "Your health is medium"  --result 4
elseif health <= 80 then                  --condition 5
return "Your health is high"        --result 5
else
return "Your health is "..health    --result if not matched (this must exist)
end
</syntaxhighlight>
 
*3. In the condition, we provides [[string]], [[table]] and following functions:
<syntaxhighlight lang="lua">
bool find( table matchTable, mixed anythingToMatch )
</syntaxhighlight>
 
*4. Then send the dictionary into DGS:
<syntaxhighlight lang="lua">
dgsSetTranslationTable("testDict",testDict) --Name,Dictionary.
</syntaxhighlight>
 
*5. Now, DGS knows that dictionary, tell DGS we want to use it:
<syntaxhighlight lang="lua">
dgsSetAttachTranslation("testDict")
</syntaxhighlight>
 
*6. Create a label, and use conditional translation:
<syntaxhighlight lang="lua">
label = dgsCreateLabel (0.51, 0.54, 0.16, 0.14, { "TestText", health=40 }, true )
</syntaxhighlight>
With DGS translation property listener, you can also do this:
<syntaxhighlight lang="lua">
label = dgsCreateLabel (0.51, 0.54, 0.16, 0.14, {"TestText", health=20 }, true )
dgsTranslationAddPropertyListener(label,"health") --Properties have higher priority than the items in text table
dgsSetProperty(label,"health","Superman")
setTimer(function()
dgsSetProperty(label,"health",60)
end,1000,1)
</syntaxhighlight>
 
==<span style="color:#000000;text-shadow:0.05em 0.05em 0.2em #00000099;">Usage 6 (Language Change)</span>==
*0. Don't forget to '''import DGS Head''' or use "'''export.dgs:'''".
*1. A '''Translation Table''' (Dictionary) should be specified:
<syntaxhighlight lang="lua">
Dict1 = {
TestText="Welcome To DGS",
}
Dict2 = {
TestText="SGD oT emocleW",
}
</syntaxhighlight>
 
*2. And, send the dictionary into DGS:
<syntaxhighlight lang="lua">
dgsSetTranslationTable("testDict",Dict1) --Name,Dictionary.
</syntaxhighlight>
 
*3. Now, DGS knows that dictionary, tell DGS we want to use it:
<syntaxhighlight lang="lua">
dgsSetAttachTranslation("testDict")
</syntaxhighlight>
 
*4. Create a label:
<syntaxhighlight lang="lua">
label = dgsCreateLabel (0.51, 0.54, 0.16, 0.14, {"TestText"}, true )
</syntaxhighlight>


'''Example'''
*4. Replace the dictionary (language changed), and you will see the text changed automatically:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
loadstring(exports.dgs:dgsImportFunction())() --Import functions before
dgsSetTranslationTable("testDict",Dict2)
loadstring(exports.dgs:dgsG2DLoadHooker())()  --Load G2D Hooker
local buttonElement = guiCreateButton(200,200,300,300,"Test",false)  --Though you are using gui functions and events, but they have already hooked by DGS
addEventHandler ( "onClientGUIClick", buttonElement, function()
outputChatBox("clicked")
end, false )
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 14:16, 28 January 2023

Description

  • 1. DGS has a built-in multilingual (multi-language) system.
  • 2. multilingual allows dynamic language changing and prevents non-essential GUI recreating or text reset by code.
  • 3. DGS multilingual system will specify the structure of Translation Table (Dictionary).

Usage 1 (Basic usage)

  • 0. Don't forget to import DGS Head or use "export.dgs:".
  • 1. A Translation Table (Dictionary) should be specified:
Dict = {
	TestText1="Welcome To DGS",
}
  • 2. And, send the dictionary into DGS:
dgsSetTranslationTable("testDict",Dict) --Name,Dictionary.
  • 3. Now, DGS knows that dictionary, we need to tell DGS we want to use it:
dgsSetAttachTranslation("testDict") --This is global setting to one resource
  • 3. Create a label:
label = dgsCreateLabel (0.51, 0.54, 0.16, 0.14, {"TestText"}, true )

Usage 2 (Basic usage)

  • 0. Don't forget to import DGS Head or use "export.dgs:".
  • 1. A Translation Table (Dictionary) should be specified:
Dict = {
	TestText1="Welcome To DGS",
}
  • 2. And, send the dictionary into DGS:
dgsSetTranslationTable("testDict",Dict) --Name,Dictionary.
  • 3. Now, DGS knows that dictionary, we can create a label and attach its text to the dictionary:
label = dgsCreateLabel (0.51, 0.54, 0.16, 0.14, {"TestText"}, true )
dgsAttachToTranslation(label,"testDict") --Only attach one element to the dictionary.

Or you can also do:

label = dgsCreateLabel (0.51, 0.54, 0.16, 0.14, "", true )
dgsAttachToTranslation(label,"testDict") --Only attach one element to the dictionary.
dgsSetText(label,{"TestText"})

Usage 3 (With parameters)

  • 0. Don't forget to import DGS Head or use "export.dgs:".
  • 1. A Translation Table (Dictionary) should be specified. And here we have an extra %rep% that takes the place of parameter:
Dict = {
	TestText1="Welcome To %rep%",
	TestText2="Welcome To %rep% %rep%",
}
  • 2. And, send the dictionary into DGS:
dgsSetTranslationTable("testDict",Dict) --Name,Dictionary.
  • 3. Now, DGS knows that dictionary, tell DGS we want to use it:
dgsSetAttachTranslation("testDict")
  • 4. Create a label, pass "DGS" as the argument
label1 = dgsCreateLabel (0.51, 0.54, 0.16, 0.14, {"TestText1","DGS"}, true )
label2 = dgsCreateLabel (0.51, 0.64, 0.16, 0.14, {"TestText2","DGS",":D"}, true )  -- 2 parameters.
label3 = dgsCreateLabel (0.51, 0.74, 0.16, 0.14, {"TestText2","DGS"}, true )  -- the rest unused '''%rep%''' will be deleted.

Usage 4 (High Level Translation)

  • 0. Don't forget to import DGS Head or use "export.dgs:".
  • 1. A Translation Table (Dictionary) should be specified. And DGS parameter support 2nd level translation:
Dict = {
	TestText="Welcome To %rep%. Have a good time %rep%",
	Smile=":)",
}
  • 2. And, send the dictionary into DGS:
dgsSetTranslationTable("testDict",Dict) --Name,Dictionary.
  • 3. Now, DGS knows that dictionary, tell DGS we want to use it:
dgsSetAttachTranslation("testDict")
  • 4. Create a label, and use 2nd level translation:
label = dgsCreateLabel (0.51, 0.54, 0.16, 0.14, {"TestText","DGS", {"Smile"}}, true )

or more

label = dgsCreateLabel (0.51, 0.54, 0.16, 0.14, {"TestText","DGS", {"TestText",{"TestText","Smile","Smile"},"Smile"}}, true )

Usage 5 (Conditional Translation)

  • 0. Don't forget to import DGS Head or use "export.dgs:".
  • 1. A Translation Table (Dictionary) should be specified. And the translation item should be a table includes conditions and results.
testDict = {
	exampleTranslation = {
		"health == 'Superman'",     "You are a superman",
		"find({0}, health)",               "Your health is 0",
		"health <= 40",                   "Your health is low",
		"health <= 60",                   "Your health is medium",
		"health <= 80",                   "Your health is high",
		"Your health is $health",
	}
}
  • 2. The table seems to be hard to understand. But actually, you can understand it like this:
if health == 'Superman' then          --condition 1
	return "You are a superman"       --result 1
elseif find({0}, health) then              --condition 2
	return "Your health is 0"              --result 2
elseif health <= 40 then                  --condition 3
	return "Your health is low"          --result 3
elseif health <= 60 then                  --condition 4
	return "Your health is medium"   --result 4
elseif health <= 80 then                  --condition 5
	return "Your health is high"         --result 5
else
	return "Your health is "..health     --result if not matched (this must exist)
end
  • 3. In the condition, we provides string, table and following functions:
	bool find( table matchTable, mixed anythingToMatch )
  • 4. Then send the dictionary into DGS:
dgsSetTranslationTable("testDict",testDict) --Name,Dictionary.
  • 5. Now, DGS knows that dictionary, tell DGS we want to use it:
dgsSetAttachTranslation("testDict")
  • 6. Create a label, and use conditional translation:
label = dgsCreateLabel (0.51, 0.54, 0.16, 0.14, { "TestText", health=40 }, true )

With DGS translation property listener, you can also do this:

label = dgsCreateLabel (0.51, 0.54, 0.16, 0.14, {"TestText", health=20 }, true )
dgsTranslationAddPropertyListener(label,"health")		--Properties have higher priority than the items in text table
dgsSetProperty(label,"health","Superman")
setTimer(function()
	dgsSetProperty(label,"health",60)
end,1000,1)

Usage 6 (Language Change)

  • 0. Don't forget to import DGS Head or use "export.dgs:".
  • 1. A Translation Table (Dictionary) should be specified:
Dict1 = {
	TestText="Welcome To DGS",
}
Dict2 = {
	TestText="SGD oT emocleW",
}
  • 2. And, send the dictionary into DGS:
dgsSetTranslationTable("testDict",Dict1) --Name,Dictionary.
  • 3. Now, DGS knows that dictionary, tell DGS we want to use it:
dgsSetAttachTranslation("testDict")
  • 4. Create a label:
label = dgsCreateLabel (0.51, 0.54, 0.16, 0.14, {"TestText"}, true )
  • 4. Replace the dictionary (language changed), and you will see the text changed automatically:
dgsSetTranslationTable("testDict",Dict2)