Created
August 29, 2018 17:19
-
-
Save SwimmingTiger/5a3b024cbdb32f88f7c4ba0f05b5f0b8 to your computer and use it in GitHub Desktop.
Paku_Totems: add i18n support; add locale: zhCN.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 4ab4be88a21e3807141a4ac20f4c7a9480a82391 Mon Sep 17 00:00:00 2001 | |
From: SwimmingTiger <[email protected]> | |
Date: Thu, 30 Aug 2018 01:16:21 +0800 | |
Subject: [PATCH] add i18n support; add locale: zhCN. | |
--- | |
Libs/AceLocale-3.0/AceLocale-3.0.lua | 137 +++++++++++++++++++++++++++++++++++ | |
Libs/AceLocale-3.0/AceLocale-3.0.xml | 4 + | |
Locales/zhCN.lua | 20 +++++ | |
Paku_Totems.lua | 36 ++++----- | |
Paku_Totems.toc | 5 ++ | |
5 files changed, 184 insertions(+), 18 deletions(-) | |
create mode 100644 Libs/AceLocale-3.0/AceLocale-3.0.lua | |
create mode 100644 Libs/AceLocale-3.0/AceLocale-3.0.xml | |
create mode 100644 Locales/zhCN.lua | |
diff --git a/Libs/AceLocale-3.0/AceLocale-3.0.lua b/Libs/AceLocale-3.0/AceLocale-3.0.lua | |
new file mode 100644 | |
index 0000000..2ecc0cb | |
--- /dev/null | |
+++ b/Libs/AceLocale-3.0/AceLocale-3.0.lua | |
@@ -0,0 +1,137 @@ | |
+--- **AceLocale-3.0** manages localization in addons, allowing for multiple locale to be registered with fallback to the base locale for untranslated strings. | |
+-- @class file | |
+-- @name AceLocale-3.0 | |
+-- @release $Id: AceLocale-3.0.lua 1035 2011-07-09 03:20:13Z kaelten $ | |
+local MAJOR,MINOR = "AceLocale-3.0", 6 | |
+ | |
+local AceLocale, oldminor = LibStub:NewLibrary(MAJOR, MINOR) | |
+ | |
+if not AceLocale then return end -- no upgrade needed | |
+ | |
+-- Lua APIs | |
+local assert, tostring, error = assert, tostring, error | |
+local getmetatable, setmetatable, rawset, rawget = getmetatable, setmetatable, rawset, rawget | |
+ | |
+-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded | |
+-- List them here for Mikk's FindGlobals script | |
+-- GLOBALS: GAME_LOCALE, geterrorhandler | |
+ | |
+local gameLocale = GetLocale() | |
+if gameLocale == "enGB" then | |
+ gameLocale = "enUS" | |
+end | |
+ | |
+AceLocale.apps = AceLocale.apps or {} -- array of ["AppName"]=localetableref | |
+AceLocale.appnames = AceLocale.appnames or {} -- array of [localetableref]="AppName" | |
+ | |
+-- This metatable is used on all tables returned from GetLocale | |
+local readmeta = { | |
+ __index = function(self, key) -- requesting totally unknown entries: fire off a nonbreaking error and return key | |
+ rawset(self, key, key) -- only need to see the warning once, really | |
+ geterrorhandler()(MAJOR..": "..tostring(AceLocale.appnames[self])..": Missing entry for '"..tostring(key).."'") | |
+ return key | |
+ end | |
+} | |
+ | |
+-- This metatable is used on all tables returned from GetLocale if the silent flag is true, it does not issue a warning on unknown keys | |
+local readmetasilent = { | |
+ __index = function(self, key) -- requesting totally unknown entries: return key | |
+ rawset(self, key, key) -- only need to invoke this function once | |
+ return key | |
+ end | |
+} | |
+ | |
+-- Remember the locale table being registered right now (it gets set by :NewLocale()) | |
+-- NOTE: Do never try to register 2 locale tables at once and mix their definition. | |
+local registering | |
+ | |
+-- local assert false function | |
+local assertfalse = function() assert(false) end | |
+ | |
+-- This metatable proxy is used when registering nondefault locales | |
+local writeproxy = setmetatable({}, { | |
+ __newindex = function(self, key, value) | |
+ rawset(registering, key, value == true and key or value) -- assigning values: replace 'true' with key string | |
+ end, | |
+ __index = assertfalse | |
+}) | |
+ | |
+-- This metatable proxy is used when registering the default locale. | |
+-- It refuses to overwrite existing values | |
+-- Reason 1: Allows loading locales in any order | |
+-- Reason 2: If 2 modules have the same string, but only the first one to be | |
+-- loaded has a translation for the current locale, the translation | |
+-- doesn't get overwritten. | |
+-- | |
+local writedefaultproxy = setmetatable({}, { | |
+ __newindex = function(self, key, value) | |
+ if not rawget(registering, key) then | |
+ rawset(registering, key, value == true and key or value) | |
+ end | |
+ end, | |
+ __index = assertfalse | |
+}) | |
+ | |
+--- Register a new locale (or extend an existing one) for the specified application. | |
+-- :NewLocale will return a table you can fill your locale into, or nil if the locale isn't needed for the players | |
+-- game locale. | |
+-- @paramsig application, locale[, isDefault[, silent]] | |
+-- @param application Unique name of addon / module | |
+-- @param locale Name of the locale to register, e.g. "enUS", "deDE", etc. | |
+-- @param isDefault If this is the default locale being registered (your addon is written in this language, generally enUS) | |
+-- @param silent If true, the locale will not issue warnings for missing keys. Must be set on the first locale registered. If set to "raw", nils will be returned for unknown keys (no metatable used). | |
+-- @usage | |
+-- -- enUS.lua | |
+-- local L = LibStub("AceLocale-3.0"):NewLocale("TestLocale", "enUS", true) | |
+-- L["string1"] = true | |
+-- | |
+-- -- deDE.lua | |
+-- local L = LibStub("AceLocale-3.0"):NewLocale("TestLocale", "deDE") | |
+-- if not L then return end | |
+-- L["string1"] = "Zeichenkette1" | |
+-- @return Locale Table to add localizations to, or nil if the current locale is not required. | |
+function AceLocale:NewLocale(application, locale, isDefault, silent) | |
+ | |
+ -- GAME_LOCALE allows translators to test translations of addons without having that wow client installed | |
+ local gameLocale = GAME_LOCALE or gameLocale | |
+ | |
+ local app = AceLocale.apps[application] | |
+ | |
+ if silent and app and getmetatable(app) ~= readmetasilent then | |
+ geterrorhandler()("Usage: NewLocale(application, locale[, isDefault[, silent]]): 'silent' must be specified for the first locale registered") | |
+ end | |
+ | |
+ if not app then | |
+ if silent=="raw" then | |
+ app = {} | |
+ else | |
+ app = setmetatable({}, silent and readmetasilent or readmeta) | |
+ end | |
+ AceLocale.apps[application] = app | |
+ AceLocale.appnames[app] = application | |
+ end | |
+ | |
+ if locale ~= gameLocale and not isDefault then | |
+ return -- nop, we don't need these translations | |
+ end | |
+ | |
+ registering = app -- remember globally for writeproxy and writedefaultproxy | |
+ | |
+ if isDefault then | |
+ return writedefaultproxy | |
+ end | |
+ | |
+ return writeproxy | |
+end | |
+ | |
+--- Returns localizations for the current locale (or default locale if translations are missing). | |
+-- Errors if nothing is registered (spank developer, not just a missing translation) | |
+-- @param application Unique name of addon / module | |
+-- @param silent If true, the locale is optional, silently return nil if it's not found (defaults to false, optional) | |
+-- @return The locale table for the current language. | |
+function AceLocale:GetLocale(application, silent) | |
+ if not silent and not AceLocale.apps[application] then | |
+ error("Usage: GetLocale(application[, silent]): 'application' - No locales registered for '"..tostring(application).."'", 2) | |
+ end | |
+ return AceLocale.apps[application] | |
+end | |
diff --git a/Libs/AceLocale-3.0/AceLocale-3.0.xml b/Libs/AceLocale-3.0/AceLocale-3.0.xml | |
new file mode 100644 | |
index 0000000..a4cf340 | |
--- /dev/null | |
+++ b/Libs/AceLocale-3.0/AceLocale-3.0.xml | |
@@ -0,0 +1,4 @@ | |
+<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ | |
+..\FrameXML\UI.xsd"> | |
+ <Script file="AceLocale-3.0.lua"/> | |
+</Ui> | |
diff --git a/Locales/zhCN.lua b/Locales/zhCN.lua | |
new file mode 100644 | |
index 0000000..d88239d | |
--- /dev/null | |
+++ b/Locales/zhCN.lua | |
@@ -0,0 +1,20 @@ | |
+local addonName = ... | |
+local L = LibStub("AceLocale-3.0"):NewLocale(addonName, "zhCN") | |
+if not L then return end | |
+ | |
+L["The Sliver (North)"] = "碎枝林地北部" | |
+L["The Sliver (South)"] = "碎枝林地南部" | |
+L["Top of Zanchul"] = "赞枢尔顶端" | |
+L["East Zanchul"] = "赞枢尔东侧" | |
+L["West Zanchul"] = "赞枢尔西侧" | |
+L["Terrace of the Chosen"] = "选民之台" | |
+L["Altar of Pa'ku"] = "帕库祭坛" | |
+L["The Great Seal Ledge"] = "巨擘封印" | |
+L["The Golden Throne"] = "黄金王座" | |
+L["Beastcaller Inn (Warbeast Kraal)"] = "驭兽师旅店 (战兽栏)" | |
+L["Grand Bazaar"] = "百商集市" | |
+L["Terrace of Crafters"] = "工匠平台" | |
+L["The Zocalo"] = "佐卡罗广场" | |
+L["The Great Seal Ledge"] = "巨擘封印" | |
+L["Grand Bazaar"] = "百商集市" | |
+ | |
diff --git a/Paku_Totems.lua b/Paku_Totems.lua | |
index cd12e79..35d7c5d 100644 | |
--- a/Paku_Totems.lua | |
+++ b/Paku_Totems.lua | |
@@ -1,7 +1,7 @@ | |
local addonName, addonSpace = ... | |
local addon = LibStub('AceAddon-3.0'):NewAddon(addonSpace, addonName, 'AceEvent-3.0') | |
---local L = LibStub('AceLocale-3.0'):GetLocale(addonName) | |
+local L = LibStub('AceLocale-3.0'):GetLocale(addonName) | |
local VERSION = GetAddOnMetadata(addonName, 'Version') | |
@@ -18,119 +18,119 @@ local totems = { | |
{ | |
dst = {0.589707016944885,0.110139846801758}, | |
src = {0.529342889785767,0.113030731678009}, | |
- name = "The Sliver (North)", | |
+ name = L["The Sliver (North)"], | |
dstMapID = 1165, | |
srcMapID = 1165, | |
}, -- [1] | |
{ | |
dst = {0.528360247612,0.118593633174896}, | |
src = {0.591121912002564,0.106748402118683}, | |
- name = "East Zanchul", | |
+ name = L["East Zanchul"], | |
dstMapID = 1165, | |
srcMapID = 1165, | |
}, -- [2] | |
{ | |
dst = {0.446326375007629,0.0604671835899353}, | |
src = {0.528954386711121,0.123093903064728}, | |
- name = "Top of Zanchul", | |
+ name = L["Top of Zanchul"], | |
dstMapID = 1165, | |
srcMapID = 1165, | |
}, -- [3] | |
{ | |
dst = {0.527879416942596,0.113702595233917}, | |
src = {0.447229325771332,0.0580671429634094}, | |
- name = "East Zanchul", | |
+ name = L["East Zanchul"], | |
dstMapID = 1165, | |
srcMapID = 1165, | |
}, -- [4] | |
{ | |
dst = {0.527620315551758,0.118496298789978}, | |
src = {0.532340049743652,0.18929660320282}, | |
- name = "East Zanchul", | |
+ name = L["East Zanchul"], | |
dstMapID = 1165, | |
srcMapID = 1165, | |
}, -- [5] | |
{ | |
dst = {0.592305719852448,0.22837620973587}, | |
src = {0.653485417366028,0.339411973953247}, | |
- name = "The Sliver (South)", | |
+ name = L["The Sliver (South)"], | |
dstMapID = 1165, | |
srcMapID = 862, | |
}, -- [6] | |
{ | |
dst = {0.465587317943573,0.197906374931335}, | |
src = {0.45066511631012,0.052379310131073}, | |
- name = "Terrace of the Chosen", | |
+ name = L["Terrace of the Chosen"], | |
dstMapID = 1165, | |
srcMapID = 1165, | |
}, -- [7] | |
{ | |
dst = {0.502696871757507,0.325962483882904}, | |
src = {0.465993463993073,0.199528515338898}, | |
- name = "Altar of Pa'ku", | |
+ name = L["Altar of Pa'ku"], | |
dstMapID = 1165, | |
srcMapID = 1165, | |
}, -- [8] | |
{ | |
dst = {0.499147057533264,0.39557409286499}, | |
src = {0.495611786842346,0.328776597976685}, | |
- name = "The Great Seal Ledge", | |
+ name = L["The Great Seal Ledge"], | |
dstMapID = 1165, | |
srcMapID = 1165, | |
}, -- [9] | |
{ | |
dst = {0.499848961830139,0.434243261814117}, | |
src = {0.513542056083679,0.409644901752472}, | |
- name = "The Golden Throne", | |
+ name = L["The Golden Throne"], | |
dstMapID = 1165, | |
srcMapID = 1165, | |
}, -- [10] | |
{ | |
dst = {0.665206968784332,0.423748135566711}, | |
src = {0.58306896686554,0.326411426067352}, | |
- name = "Beastcaller Inn (Warbeast Kraal)", | |
+ name = L["Beastcaller Inn (Warbeast Kraal)"], | |
dstMapID = 862, | |
srcMapID = 1165, | |
}, -- [11] | |
{ | |
dst = {0.468166947364807,0.856901288032532}, | |
src = {0.55028235912323,0.417159020900726}, | |
- name = "Grand Bazaar", | |
+ name = L["Grand Bazaar"], | |
dstMapID = 1165, | |
srcMapID = 862, | |
}, -- [12] | |
{ | |
dst = {0.551357746124268,0.417158424854279}, | |
src = {0.469304084777832,0.855770230293274}, | |
- name = "Terrace of Crafters", | |
+ name = L["Terrace of Crafters"], | |
dstMapID = 862, | |
srcMapID = 1165, | |
}, -- [13] | |
{ | |
dst = {0.408991038799286,0.107170045375824}, | |
src = {0.427186667919159,0.229450643062592}, | |
- name = "West Zanchul", | |
+ name = L["West Zanchul"], | |
dstMapID = 1165, | |
srcMapID = 1165, | |
}, -- [14] | |
{ | |
dst = {0.425679862499237,0.231258273124695}, | |
src = {0.407363951206207,0.111508727073669}, | |
- name = "The Zocalo", | |
+ name = L["The Zocalo"], | |
dstMapID = 1165, | |
srcMapID = 1165, | |
}, -- [15] | |
{ | |
dst = {0.49884170293808,0.3972989320755}, | |
src = {0.550585150718669,0.42086488008499}, | |
- name = "The Great Seal Ledge", | |
+ name = L["The Great Seal Ledge"], | |
dstMapID = 1165, | |
srcMapID = 862, | |
}, -- [16] | |
{ | |
dst = {0.46906685829163,0.85581636428833}, | |
src = {0.40843677520752,0.84118854999542}, | |
- name = "Grand Bazaar", | |
+ name = L["Grand Bazaar"], | |
dstMapID = 1165, | |
srcMapID = 1165, | |
}, -- [17] | |
diff --git a/Paku_Totems.toc b/Paku_Totems.toc | |
index 8f0fafe..4e519f0 100644 | |
--- a/Paku_Totems.toc | |
+++ b/Paku_Totems.toc | |
@@ -1,8 +1,10 @@ | |
## Interface: 80000 | |
## Title: Pa'ku Totems | |
+## Title-zhCN: 帕库的图腾 | |
## Author: jaxdahl | |
## Version: 1.32 | |
## Notes: Show Pa'ku totem positions on the map and destinations in the tooltip on mouseover. | |
+## Notes-zhCN: 在地图上显示帕库图腾的位置,并在鼠标指向图腾时提示目的地。 | |
Libs\LibStub\LibStub.lua | |
Libs\CallbackHandler-1.0\CallbackHandler-1.0.lua | |
@@ -12,5 +14,8 @@ Libs\HereBeDragons-2.0\HereBeDragons-Pins-2.0.lua | |
Libs\AceAddon-3.0\AceAddon-3.0.xml | |
Libs\AceEvent-3.0\AceEvent-3.0.xml | |
+Libs\AceLocale-3.0\AceLocale-3.0.xml | |
+ | |
+Locales\zhCN.lua | |
Paku_Totems.lua | |
-- | |
2.7.4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment