Skip to content

Commit 337e41e

Browse files
committed
Improved the script to automate localization
1 parent 7b36da3 commit 337e41e

File tree

13 files changed

+57
-73
lines changed

13 files changed

+57
-73
lines changed

.github/scripts/find-locale-strings.lua

Lines changed: 45 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,83 @@
1-
-- Thanks to Nevcairiel @ https://github.com/Nevcairiel/Bartender4/blob/master/locale/find-locale-strings.lua
2-
local TOC_FILES = {}
1+
-- Inspired by https://github.com/Nevcairiel/Bartender4/blob/master/locale/find-locale-strings.lua
2+
local LUA_FILES = {}
33
-- Automatically find the TOC in the given path, set to false to disable
44
local outputFilename = arg and arg[1] or "exported-locale-strings.lua"
5-
local AUTO_FIND_TOC = { "./" }
5+
local PATHS = { "./" }
66
if arg and arg[2] then
77
local i = 2
88
while arg[i] do
9-
AUTO_FIND_TOC[i-1] = arg[i]
9+
PATHS[i - 1] = arg[i]
1010
i = i + 1
1111
end
1212
end
1313

1414
-- Patterns that should not be scrapped, case-insensitive
1515
-- Anything between the no-lib-strip is automatically ignored
16-
local FILE_BLACKLIST = {"^locale", "^libs"}
16+
local FILE_BLACKLIST = { "/locale/", "/libs/", "/types.lua" }
1717

1818

1919
-- No more modifying!
2020
local OS_TYPE = os.getenv("HOME") and "linux" or "windows"
21+
if OS_TYPE == "windows" then
22+
error("Only Linux is supported at this time.")
23+
end
2124

22-
-- Find the TOC now
23-
for _, path in ipairs(AUTO_FIND_TOC) do
24-
local pipe = OS_TYPE == "windows" and io.popen(string.format("dir /B \"%s\"", path)) or io.popen(string.format("ls -1 \"%s\"", path))
25-
if( type(pipe) == "userdata" ) then
25+
for _, path in ipairs(PATHS) do
26+
local pipe = io.popen(string.format("find \"%s\" -type f -name '*.lua'", path))
27+
if type(pipe) == "userdata" then
2628
for file in pipe:lines() do
27-
if( string.match(file, "(.+)%.toc") ) then
28-
table.insert(TOC_FILES, { path = path, toc = path .. file })
29-
break
29+
if string.match(file, "(.+)%.lua") then
30+
table.insert(LUA_FILES, file)
3031
end
3132
end
3233

3334
pipe:close()
34-
if( not TOC_FILES ) then print("Failed to auto detect toc file.") end
3535
else
36-
print("Failed to auto find toc, cannot run dir /B or ls -1")
36+
error("Failed to auto find lua files")
3737
end
3838
end
3939

40-
if( not next(TOC_FILES) ) then
41-
return
40+
if not next(LUA_FILES) then
41+
error("Failed to auto detect toc file.")
4242
end
4343

44-
local ignore
4544
local localizedKeys = {}
46-
for _, tocFile in ipairs(TOC_FILES) do
47-
local toc, path = tocFile.toc, tocFile.path
48-
print(string.format("Using TOC file %s", toc))
49-
print("")
50-
-- Parse through the TOC file so we know what to scan
51-
for line in io.lines(toc) do
52-
line = path .. string.gsub(line, "\r", "")
53-
54-
if( string.match(line, "#@no%-lib%-strip@") ) then
55-
ignore = true
56-
elseif( string.match(line, "#@end%-no%-lib%-strip@") ) then
57-
ignore = nil
45+
for _, file in ipairs(LUA_FILES) do
46+
if string.match(file, "%.lua") and not string.match(file, "^%s*#") then
47+
-- Make sure it's a valid file
48+
local blacklist
49+
for _, check in pairs(FILE_BLACKLIST) do
50+
if string.match(string.lower(file), check) then
51+
blacklist = true
52+
break
53+
end
5854
end
5955

60-
if( not ignore and string.match(line, "%.lua") and not string.match(line, "^%s*#")) then
61-
-- Make sure it's a valid file
62-
local blacklist
63-
for _, check in pairs(FILE_BLACKLIST) do
64-
if( string.match(string.lower(line), check) ) then
65-
blacklist = true
66-
break
67-
end
56+
-- File checks out, scrap everything
57+
if not blacklist then
58+
-- Fix slashes
59+
if OS_TYPE == "linux" then
60+
file = string.gsub(file, "\\", "/")
6861
end
6962

70-
-- File checks out, scrap everything
71-
if( not blacklist ) then
72-
-- Fix slashes
73-
if( OS_TYPE == "linux" ) then
74-
line = string.gsub(line, "\\", "/")
75-
end
76-
77-
local keys = 0
78-
local contents = io.open(line):read("*all")
79-
80-
for match in string.gmatch(contents, "L%[\"(.-)\"]") do
81-
if( not localizedKeys[match] ) then keys = keys + 1 end
82-
localizedKeys[match] = true
83-
end
84-
for match in string.gmatch(contents, "L%['(.-)']") do
85-
-- convert format from single to double quotes
86-
match = string.gsub(match, "\\'", "'")
87-
match = string.gsub(match, "\"", "\\\"")
88-
if( not localizedKeys[match] ) then keys = keys + 1 end
89-
localizedKeys[match] = true
90-
end
63+
local keys = 0
64+
local contents = io.open(file):read("*all")
9165

92-
print(string.format("%s (%d keys)", line, keys))
66+
for match in string.gmatch(contents, "L%[\"(.-)\"]") do
67+
if not localizedKeys[match] then keys = keys + 1 end
68+
localizedKeys[match] = true
9369
end
70+
for match in string.gmatch(contents, "L%['(.-)']") do
71+
-- convert format from single to double quotes
72+
match = string.gsub(match, "\\'", "'")
73+
match = string.gsub(match, "\"", "\\\"")
74+
if not localizedKeys[match] then keys = keys + 1 end
75+
localizedKeys[match] = true
76+
end
77+
78+
print(string.format("%s (%d keys)", file, keys))
9479
end
9580
end
96-
print("")
9781
end
9882

9983
-- Compile all of the localization we found into string form
@@ -104,7 +88,7 @@ for key in pairs(localizedKeys) do
10488
totalLocalizedKeys = totalLocalizedKeys + 1
10589
end
10690

107-
if( totalLocalizedKeys == 0 ) then
91+
if totalLocalizedKeys == 0 then
10892
print("Warning, failed to find any localizations, perhaps you messed up a configuration variable?")
10993
return
11094
end

.github/scripts/update_translation.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Thanks to Nevcairiel @ https://github.com/Nevcairiel/Bartender4/blob/master/locale/wowace-locale-import.sh
2+
# Inspired by https://github.com/Nevcairiel/Bartender4/blob/master/locale/wowace-locale-import.sh
33

44
cf_token=
55

locale/deDE.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Please use the Localization App on CurseForge to Update this
1+
-- Please use the Localization App on CurseForge to update this file
22
-- https://legacy.curseforge.com/wow/addons/talent-tree-tweaks/localization
33
local name, _ = ...
44

locale/enUS.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Please use the Localization App on CurseForge to Update this
1+
-- Please use the Localization App on CurseForge to update this file
22
-- https://legacy.curseforge.com/wow/addons/talent-tree-tweaks/localization
33
local name, _ = ...
44

locale/esES.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Please use the Localization App on CurseForge to Update this
1+
-- Please use the Localization App on CurseForge to update this file
22
-- https://legacy.curseforge.com/wow/addons/talent-tree-tweaks/localization
33
local name, _ = ...
44

locale/frFR.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Please use the Localization App on CurseForge to Update this
1+
-- Please use the Localization App on CurseForge to update this file
22
-- https://legacy.curseforge.com/wow/addons/talent-tree-tweaks/localization
33
local name, _ = ...
44

locale/itIT.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Please use the Localization App on CurseForge to Update this
1+
-- Please use the Localization App on CurseForge to update this file
22
-- https://legacy.curseforge.com/wow/addons/talent-tree-tweaks/localization
33
local name, _ = ...
44

locale/koKR.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Please use the Localization App on CurseForge to Update this
1+
-- Please use the Localization App on CurseForge to update this file
22
-- https://legacy.curseforge.com/wow/addons/talent-tree-tweaks/localization
33
local name, _ = ...
44

locale/locale.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<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/
2-
..\FrameXML\UI.xsd">
2+
https://raw.githubusercontent.com/Meorawr/wow-ui-schema/main/UI.xsd">
33
<Script file="enUS.lua"/>
44
<Script file="deDE.lua"/>
55
<Script file="frFR.lua"/>

locale/ptBR.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Please use the Localization App on CurseForge to Update this
1+
-- Please use the Localization App on CurseForge to update this file
22
-- https://legacy.curseforge.com/wow/addons/talent-tree-tweaks/localization
33
local name, _ = ...
44

0 commit comments

Comments
 (0)