From b35368ad0a793fe5037a1094d7e4e082c77d598f Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sun, 11 Aug 2013 08:33:24 -0700 Subject: Initial commit --- LICENSE | 20 ++++++++++++++++++++ README.md | 4 ++++ 2 files changed, 24 insertions(+) create mode 100644 LICENSE create mode 100644 README.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..102ed2a36 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2013 Alexander Harkness + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 000000000..476ecdcb6 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +transapi +======== + +A Translation API for MCServer -- cgit v1.2.3 From 0d97cd77fdee94f5bd5e2b89f645a84e62dc8da9 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Mon, 12 Aug 2013 21:15:53 +0100 Subject: Did some stuff. --- main.lua | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 main.lua diff --git a/main.lua b/main.lua new file mode 100644 index 000000000..e8d7d7990 --- /dev/null +++ b/main.lua @@ -0,0 +1,54 @@ +-- This plugin copyright Alexander Harkness 2013, licensed under the MIT license. + +-- Configuration +g_ServerLang = "english" +g_ConsoleLang = "english" + +-- Global Variables +g_Plugin = nil +g_PluginManager = nil +g_PluginDir = nil +g_UserData + +-- START WITH DA AWESOME! +function Initialize( Plugin ) + + -- Set up the globals. + g_Plugin = Plugin + g_PluginManager = cRoot:Get():GetPluginManager() + g_PluginDir = Plugin:GetDirectory() + + -- Set up the plugin details. + Plugin:SetName( "TransAPI" ) + Plugin:SetVersion( 1 ) + + -- This is the place for commands! + PluginManager:BindCommand("/language", "transapi.setlang", HandleLanguageCommand, " - Set your preferred language.") + + -- Load the userdata file. + + + LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() ) + + return true + +end + +function GetLanguage( user ) + + -- Returns a language to use. + +end + +function GetConsoleLanguage() + -- Return the language to use for console messages. + return g_ConsoleLang +end + +function HandleLanguageCommand ( Split, Player ) + return true +end + +function OnDisable() + LOG( "Disabled TransAPI!" ) +end -- cgit v1.2.3 From ff7e4b5bb9e1c5c567043ad8479a054c0c085f5e Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Tue, 13 Aug 2013 09:39:42 +0100 Subject: Finished up the main plugin. --- main.lua | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/main.lua b/main.lua index e8d7d7990..da1fdda7d 100644 --- a/main.lua +++ b/main.lua @@ -1,14 +1,14 @@ -- This plugin copyright Alexander Harkness 2013, licensed under the MIT license. -- Configuration -g_ServerLang = "english" -g_ConsoleLang = "english" +g_ServerLang = "english" +g_ConsoleLang = "english" -- Global Variables -g_Plugin = nil +g_Plugin = nil g_PluginManager = nil -g_PluginDir = nil -g_UserData +g_PluginDir = nil +g_UserData = nil -- START WITH DA AWESOME! function Initialize( Plugin ) @@ -23,10 +23,13 @@ function Initialize( Plugin ) Plugin:SetVersion( 1 ) -- This is the place for commands! - PluginManager:BindCommand("/language", "transapi.setlang", HandleLanguageCommand, " - Set your preferred language.") + g_PluginManager:BindCommand("/language", "transapi.setlang", HandleLanguageCommand, " - Set your preferred language.") -- Load the userdata file. - + g_UserData = cIniFile( g_PluginDir .. "/userdata.ini" ) + if g_UserData ~= true then + LOGERROR( "TransAPI INI file could not be opened!" ) + end LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() ) @@ -34,9 +37,19 @@ function Initialize( Plugin ) end -function GetLanguage( user ) +function GetLanguage( Player ) -- Returns a language to use. + if g_UserData:ReadFile() == true then + local userLang = g_UserData:GetValueSet( Player:GetName(), "language", "false" ) + g_UserData:WriteFile() + end + + if userLang == "false" then + return g_ServerLang + else + return userLang + end end @@ -46,7 +59,31 @@ function GetConsoleLanguage() end function HandleLanguageCommand ( Split, Player ) + + -- If the user is not setting the language, tell them the currently selected one. + if #Split ~= 2 then + + local userLang = g_UserData:GetValueSet( Player:GetName(), "language", "false" ) + if userLang == "false" then + return g_ServerLang + else + return userLang + end + + end + + -- Set the language. + local success = g_UserData:SetValue( Player:GetName(), "language" Split[2] ) + g_UserData:WriteFile() + + if not success then + Player:SendMessage( "Language could not be set!" ) + else + Player:SendMessage( "Language set!" ) + end + return true + end function OnDisable() -- cgit v1.2.3 From 40094c2620248c0f79df12e5860bf6eb26614f75 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Tue, 13 Aug 2013 09:46:15 +0100 Subject: Changed system to use ISO 639-1. --- main.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.lua b/main.lua index da1fdda7d..2b6f77da6 100644 --- a/main.lua +++ b/main.lua @@ -1,8 +1,8 @@ -- This plugin copyright Alexander Harkness 2013, licensed under the MIT license. -- Configuration -g_ServerLang = "english" -g_ConsoleLang = "english" +g_ServerLang = "en" +g_ConsoleLang = "en" -- Global Variables g_Plugin = nil @@ -23,7 +23,7 @@ function Initialize( Plugin ) Plugin:SetVersion( 1 ) -- This is the place for commands! - g_PluginManager:BindCommand("/language", "transapi.setlang", HandleLanguageCommand, " - Set your preferred language.") + g_PluginManager:BindCommand("/language", "transapi.setlang", HandleLanguageCommand, " - Set your preferred language (use ISO 639-1)") -- Load the userdata file. g_UserData = cIniFile( g_PluginDir .. "/userdata.ini" ) -- cgit v1.2.3 From ce761fa2b874d40c49a4aa44f3a2b751c725ae6e Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Tue, 13 Aug 2013 09:47:43 +0100 Subject: Made the README --- README.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 476ecdcb6..855c4bd4b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,20 @@ -transapi +TransAPI ======== -A Translation API for MCServer +A plugin translation API for MCServer. + +TransAPI is designed to be used with the provided client library, however there is also a stable API available for use. + +API +--- + + GetLanguage ( cPlayer ) + Returns the user's preferred language (or server default if not set). (ISO 639-1 language code) + + GetConsoleLanguage ( ) + Returns the preferred language for console text. (ISO 639-1 language code) + +Commands +-------- + + * /language [lang] - Takes a language code (ISO 639-1) and sets the user's preferred language to that. (tranapi.setlang) -- cgit v1.2.3 From 52e1de4332a026e58fda843aae98c1f51e57199e Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Tue, 13 Aug 2013 09:50:15 +0100 Subject: Added link to future lib. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 855c4bd4b..b037a6732 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ TransAPI A plugin translation API for MCServer. -TransAPI is designed to be used with the provided client library, however there is also a stable API available for use. +TransAPI is designed to be used with the [client library](https://github.com/bearbin/transapi-client), however there is also a stable API available for use. API --- -- cgit v1.2.3 From 3e5b74fa026d931220af5568bfe4080b46ae8c73 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Tue, 13 Aug 2013 18:35:31 +0100 Subject: Added TransAPI as a default plugin. --- MCServer/settings.example.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/MCServer/settings.example.ini b/MCServer/settings.example.ini index e2505368d..3daeb00f1 100644 --- a/MCServer/settings.example.ini +++ b/MCServer/settings.example.ini @@ -18,6 +18,7 @@ DefaultWorld=world Plugin=Core Plugin=ChunkWorx Plugin=ChatLog +Plugin=TransAPI [Monsters] AnimalsOn=0 -- cgit v1.2.3