Merge pull request #244 from DrahcPro/dev

Language detection module
This commit is contained in:
Cooldude2606
2023-08-15 19:30:19 +01:00
committed by GitHub
52 changed files with 135 additions and 0 deletions

View File

@@ -78,6 +78,7 @@ return {
'modules.data.tag',
'modules.data.bonus',
'modules.data.personal-logistic',
'modules.data.language',
--- GUI
'modules.gui.readme',

2
locale/af/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Afrikaans

2
locale/ar/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Arabic

2
locale/be/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Belarusian

2
locale/bg/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Bulgarian

2
locale/ca/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Catalan

2
locale/cs/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Czech

2
locale/da/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Danish

2
locale/de/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=German

2
locale/el/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Greek

2
locale/en/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=English

2
locale/eo/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Esperanto

View File

@@ -0,0 +1,2 @@
[language]
local-language=Spanish (Spain)

2
locale/et/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Estonian

2
locale/eu/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Basque

2
locale/fa/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Persian

2
locale/fi/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Finnish

2
locale/fil/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Filipino

2
locale/fr/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=French

View File

@@ -0,0 +1,2 @@
[language]
local-language=Frysian (Netherlands)

View File

@@ -0,0 +1,2 @@
[language]
local-language=Irish (Ireland)

2
locale/he/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Hebrew

2
locale/hr/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Croatian

2
locale/hu/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Hungarian

2
locale/id/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Indonesian

2
locale/is/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Icelandic

2
locale/it/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Italian

2
locale/ja/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Japanese

2
locale/ka/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Georgian

2
locale/kk/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Kazakh

2
locale/ko/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Korean

2
locale/lt/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Lithuanian

2
locale/lv/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Latvian

2
locale/nl/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Dutch

2
locale/no/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Norwegian (Norway)

2
locale/pl/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Polish

View File

@@ -0,0 +1,2 @@
[language]
local-language=Portuguese (Brazil)

View File

@@ -0,0 +1,2 @@
[language]
local-language=Portuguese (Portugal)

2
locale/ro/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Romanian

2
locale/ru/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Russian

2
locale/sk/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Slovak

2
locale/sl/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Slovenian

2
locale/sq/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Albanian

2
locale/sr/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Serbian

View File

@@ -0,0 +1,2 @@
[language]
local-language=Swedish (Sweden)

2
locale/th/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Thai

2
locale/tr/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Turkish

2
locale/uk/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Ukrainian

2
locale/vi/language.cfg Normal file
View File

@@ -0,0 +1,2 @@
[language]
local-language=Vietnamese

View File

@@ -0,0 +1,2 @@
[language]
local-language=Chinese (Simplified)

View File

@@ -0,0 +1,2 @@
[language]
local-language=Chinese (Traditional)

34
modules/data/language.lua Normal file
View File

@@ -0,0 +1,34 @@
--- Stores the language used to join the server
-- @data Language
local Event = require 'utils.event' ---@dep utils.event
local PlayerData = require 'expcore.player_data' --- @dep expcore.player_data
local LocalLanguage = PlayerData.Statistics:combine('LocalLanguage')
LocalLanguage:set_default("Unknown")
--- Creates translation request on_load of a player
LocalLanguage:on_load(function(player_name, _)
local player = game.players[player_name]
player.request_translation({"language.local-language"})
end)
--- Resolves translation request for language setting
Event.add(defines.events.on_string_translated, function(event)
-- Check if event.localised_string is a table
-- Check if the translation request was for language setting
if type(event.localised_string) ~= "table" or event.localised_string[1] ~= "language.local-language" then
return
end
-- Check if the translation request was succesful
local player = game.players[event.player_index]
if not event.translated then
player.print("Could not detect your language settings")
-- Raise error
return
end
-- Change LocalLanguage value for the player to the recognized one
local language = event.result
LocalLanguage:set(player, language)
end)