Add the script used for creating & loading YAML
This commit is contained in:
parent
2184d7485c
commit
aa5db10ff4
100
!lang.sk
Normal file
100
!lang.sk
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
|
||||||
|
#delete language cache after 7 server restarts (not sure if this is exactly a good design xD)
|
||||||
|
on skript load:
|
||||||
|
add 1 to {langlimit}
|
||||||
|
if {langlimit} is higher than 7:
|
||||||
|
delete {langmsg::*}
|
||||||
|
on script load:
|
||||||
|
send "LOADING GLOBAL LANGUAGE FILES" to console
|
||||||
|
set {_languages::*} to "EN", "LT", "RU", "ES", "DA", "PT"
|
||||||
|
loop {_languages::*}:
|
||||||
|
set {languageslist::%loop-value%} to loop-value
|
||||||
|
|
||||||
|
loop {languageslist::*}:
|
||||||
|
#load it in memory so we can always have it loaded
|
||||||
|
load yaml "plugins/Skript/scripts/languages/Language%loop-value%.yml" as "lang%loop-value%"
|
||||||
|
|
||||||
|
#clear non-existent messages that have been removed from original EN file, but still exist in other languages
|
||||||
|
|
||||||
|
loop-value is not "EN":
|
||||||
|
|
||||||
|
loop yaml nodes from "lang%loop-value%":
|
||||||
|
|
||||||
|
yaml value loop-value-2 from "langEN" is not set:
|
||||||
|
|
||||||
|
send "Removed Non-existent message: %loop-value-2% from %loop-value-1%" to console and ops
|
||||||
|
delete yaml value loop-value-2 from "lang%loop-value-1%"
|
||||||
|
set {_deleted} to true
|
||||||
|
|
||||||
|
{_deleted} is set:
|
||||||
|
save yaml "lang%loop-value%"
|
||||||
|
delete {_deleted}
|
||||||
|
|
||||||
|
send "FINISHED LOADING GLOBAL LANGUAGE FILES" to console
|
||||||
|
function translate(message: text, receivers: objects, returntype: integer = 1, variables: strings = "null") :: text:
|
||||||
|
loop {_receivers::*}:
|
||||||
|
|
||||||
|
#support both UUIDS and player names for getting language of the player
|
||||||
|
|
||||||
|
set {_uuid} to {uuid::%loop-value%} if {name::%loop-value%} is not set else loop-value
|
||||||
|
|
||||||
|
#{_lang} variable is deleted because of multiple receivers, so if their language variable happens to be unset, they wouldn't inherit language from past player in the loop
|
||||||
|
delete {_lang}
|
||||||
|
set {_lang} to epic variable "%{_uuid}%::language" ? "EN"
|
||||||
|
if {langmsg::%{_lang}%::%{_message}%} is not set:
|
||||||
|
|
||||||
|
#if somehow the player happens to be using a non-existent language, set it to english
|
||||||
|
if {languageslist::%{_lang}%} is not set:
|
||||||
|
set {_lang} to "EN"
|
||||||
|
|
||||||
|
#format the index
|
||||||
|
set {_index} to convert string uncolored {_message} to lowercase
|
||||||
|
replace all ":" and "'" and """" and "." and " " and "[" and "]" and "," and "!" and "?" and "*" and "^" and "%%" and "##" and "@" and "(" and ")" and "-" and "_" and "+" and "=" and "`" and "~" and "$" and "|" and "{" and "}" and "<" and ">" with "" in {_index}
|
||||||
|
|
||||||
|
#detect if the message hasn't been added to YAML file, if so, auto add it!
|
||||||
|
|
||||||
|
yaml value "%{_index}%" from "lang%{_lang}%" is not set:
|
||||||
|
loop {languageslist::*}:
|
||||||
|
#check if the message isn't present in any other languages, if it isn't present, add it!
|
||||||
|
|
||||||
|
#one little issue about this, it results into double value check for current language, but I think optimizing that would be simply pointless (much less clean code)
|
||||||
|
yaml value "%{_index}%" from "lang%loop-value-2%" is not set:
|
||||||
|
set yaml value "%{_index}%" from "lang%loop-value-2%" to "%{_message}%"
|
||||||
|
save yaml "lang%loop-value-2%"
|
||||||
|
|
||||||
|
#save the message to memory + CSV file that gets auto-loaded into memory on server startup (maybe I'll save this to mysql instead for future)
|
||||||
|
|
||||||
|
set {langmsg::%{_lang}%::%{_message}%} to {_message}
|
||||||
|
|
||||||
|
#if yaml value is present, but it is not loaded into memory, load it!
|
||||||
|
else:
|
||||||
|
set {langmsg::%{_lang}%::%{_message}%} to yaml value "%{_index}%" from "lang%{_lang}%"
|
||||||
|
|
||||||
|
#since INDEX generation in my yaml files may not be always unique if the messages are extremely similar, but only with differing color codes, this unused code checks for index duplication
|
||||||
|
|
||||||
|
#set {_msgc} to yaml value "%{_index}%" from "langEN"
|
||||||
|
#{_msgc} is not {_message}:
|
||||||
|
#send "LANGUAGE: %{_msgc}%&2 does not equal to &r%{_message}%&2 | this might be a bug of different colorcodes." to ops and console
|
||||||
|
#log "LANGUAGE: %{_msgc}% does not equal to %{_message}% | this might be a bug of different colorcodes." to "language-errors.log"
|
||||||
|
|
||||||
|
#get the translated message which should be sent
|
||||||
|
|
||||||
|
set {_msg} to {langmsg::%{_lang}%::%{_message}%}
|
||||||
|
|
||||||
|
|
||||||
|
#replace $1$, $2$, etc. stuff into proper values (function providers arguments for it)
|
||||||
|
if {_variables::1} is not "null":
|
||||||
|
loop {_variables::*}:
|
||||||
|
{_msg} contains "$%loop-index-2%$":
|
||||||
|
replace "$%loop-index-2%$" with loop-value-2 in {_msg}
|
||||||
|
else:
|
||||||
|
exit loop
|
||||||
|
|
||||||
|
#Translation Mode 1, return the message (MOST USEFUL!)
|
||||||
|
if {_returntype} is 1:
|
||||||
|
return {_msg}
|
||||||
|
|
||||||
|
#Translation Mode 2, send the message in chat!
|
||||||
|
#not a good idea if trying to send a message to a separate server (as this one will work only on the same server)
|
||||||
|
else if {_returntype} is 2:
|
||||||
|
send {_msg} to loop-value
|
Loading…
Reference in New Issue
Block a user