initial release
This commit is contained in:
5473
cosmic rage/locale/Localize_template.lua
Normal file
5473
cosmic rage/locale/Localize_template.lua
Normal file
File diff suppressed because it is too large
Load Diff
88
cosmic rage/locale/count_locale_usage.lua
Normal file
88
cosmic rage/locale/count_locale_usage.lua
Normal file
@@ -0,0 +1,88 @@
|
||||
|
||||
-- make copy of original tables
|
||||
orig_messages = messages
|
||||
orig_formatted = formatted
|
||||
orig_times = times
|
||||
orig_headings = headings
|
||||
|
||||
-- empty them out so __index is triggered
|
||||
-- save original tables so we can look them up eventually
|
||||
|
||||
messages = { _orig = orig_messages }
|
||||
formatted = { _orig = orig_formatted }
|
||||
times = { _orig = orig_times }
|
||||
headings = { _orig = orig_headings }
|
||||
|
||||
counts = {} -- keep counts here
|
||||
|
||||
-- metatable for messages, titles, headings
|
||||
mt_static = {
|
||||
-- called to access an entry
|
||||
__index=
|
||||
function (t, name)
|
||||
local s = rawget (t._orig, name)
|
||||
if s == nil or #s == 0 then
|
||||
counts [name] = (counts [name] or 0) + 1
|
||||
end -- not translated yet
|
||||
return s
|
||||
end;
|
||||
}
|
||||
|
||||
-- metatable for formatted messages
|
||||
mt_formatted = {
|
||||
-- called to access an entry
|
||||
__index=
|
||||
function (t, name)
|
||||
local f = rawget (t._orig, name)
|
||||
-- no function? not translated then
|
||||
if f == nil then
|
||||
counts [name] = (counts [name] or 0) + 1
|
||||
return nil
|
||||
end
|
||||
assert (type (f) == "function")
|
||||
|
||||
-- return a function, that will count if the original function
|
||||
-- returns an empty string
|
||||
return function (...)
|
||||
local s = f (...) -- call original function
|
||||
if type (s) ~= "string" or #s == 0 then
|
||||
counts [name] = (counts [name] or 0) + 1
|
||||
end -- not translated
|
||||
return s -- return translated value
|
||||
end -- function
|
||||
end;
|
||||
}
|
||||
|
||||
-- apply the metatables
|
||||
setmetatable (messages, mt_static)
|
||||
setmetatable (times, mt_static)
|
||||
setmetatable (headings, mt_static)
|
||||
setmetatable (formatted, mt_formatted)
|
||||
|
||||
-- the user will call world.TranslateDebug to invoke this
|
||||
function Debug ()
|
||||
|
||||
-- for sorting
|
||||
local t = {}
|
||||
|
||||
-- build into table which can be sorted
|
||||
for k, v in pairs (counts) do
|
||||
table.insert (t, k)
|
||||
end -- for
|
||||
|
||||
-- clear out notepad, make heading
|
||||
utils.appendtonotepad ("translation", "Translation counts\n\n", true)
|
||||
|
||||
-- sort into descending order
|
||||
table.sort (t, function (a, b)
|
||||
return counts [a] > counts [b]
|
||||
end)
|
||||
|
||||
-- display results
|
||||
for k, v in ipairs (t) do
|
||||
utils.appendtonotepad ("translation", string.format ("%4i: %q \n", counts [v], v))
|
||||
end -- for
|
||||
|
||||
end -- Debug
|
||||
|
||||
|
||||
67
cosmic rage/locale/detect_locale_changes.lua
Normal file
67
cosmic rage/locale/detect_locale_changes.lua
Normal file
@@ -0,0 +1,67 @@
|
||||
-- stuff already localized
|
||||
locale = "en" -- change to suit you
|
||||
|
||||
dofile (locale .. ".lua")
|
||||
|
||||
-- make copy
|
||||
original = {
|
||||
messages = messages,
|
||||
formatted = formatted,
|
||||
times = times,
|
||||
headings = headings
|
||||
}
|
||||
|
||||
messages, formatted, times, headings = nil
|
||||
|
||||
-- from distribution
|
||||
dofile ("Localize_template.lua")
|
||||
|
||||
-- make copy
|
||||
distribution = {
|
||||
messages = messages,
|
||||
formatted = formatted,
|
||||
times = times,
|
||||
headings = headings
|
||||
}
|
||||
|
||||
messages, formatted, times, headings = nil
|
||||
|
||||
function compare_table (name)
|
||||
local count = 0
|
||||
local old = original [name]
|
||||
local new = distribution [name]
|
||||
|
||||
print ("Processing table", name)
|
||||
print ""
|
||||
|
||||
-- new message is in distribution, but not in already localized file
|
||||
for k, v in pairs (new) do
|
||||
if not old [k] then
|
||||
count = count + 1
|
||||
print (string.format (" New message: %q", k))
|
||||
end -- if not there
|
||||
end -- for
|
||||
|
||||
|
||||
print ("Found ", count, " new messages")
|
||||
print ""
|
||||
|
||||
count = 0
|
||||
|
||||
-- old message is in already localized file, but not in distribution
|
||||
for k, v in pairs (old) do
|
||||
if not new [k] then
|
||||
count = count + 1
|
||||
print (string.format (" Deleted message: %q", k))
|
||||
end -- if not there
|
||||
end -- for
|
||||
|
||||
print ("Found ", count, " deleted messages")
|
||||
print ""
|
||||
|
||||
end -- compare_table
|
||||
|
||||
compare_table ("messages")
|
||||
compare_table ("formatted")
|
||||
compare_table ("times")
|
||||
compare_table ("headings")
|
||||
BIN
cosmic rage/locale/en.dll
Normal file
BIN
cosmic rage/locale/en.dll
Normal file
Binary file not shown.
BIN
cosmic rage/locale/en_small.dll
Normal file
BIN
cosmic rage/locale/en_small.dll
Normal file
Binary file not shown.
84
cosmic rage/locale/locale_notes.txt
Normal file
84
cosmic rage/locale/locale_notes.txt
Normal file
@@ -0,0 +1,84 @@
|
||||
Localization notes
|
||||
------------------
|
||||
|
||||
Author: Nick Gammon
|
||||
Date: 18th June 2007
|
||||
Amended: 27th May 2008 to mention large/small monitor handling
|
||||
|
||||
|
||||
In the "locale" directory - which is a subdirectory under where the MUSHclient.exe program is stored, you should find the following files in the standard MUSHclient distribution:
|
||||
|
||||
* locale_notes.txt --> this file
|
||||
|
||||
* Localize_template.lua --> template for creating a new translation file
|
||||
|
||||
* en.dll --> resources for MUSHclient - in English (for screen resolution 1024 x 768 or larger)
|
||||
|
||||
* en_small.dll --> resources for MUSHclient - in English (for small screen resolutions)
|
||||
|
||||
* count_locale_usage.lua --> Lua script for counting which messages need translating the most
|
||||
|
||||
* detect_locale_changes.lua --> Lua script for detecting changes between one MUSHclient distribution and the next
|
||||
|
||||
|
||||
See the following forum posting for detailed descriptions about localizing MUSHclient:
|
||||
|
||||
http://www.gammon.com.au/forum/?id=7953
|
||||
|
||||
|
||||
To localize
|
||||
-----------
|
||||
|
||||
If you are planning to localize to another language, you would take these steps. Let us take French as an example, which has a locale code of FR.
|
||||
|
||||
1. Copy en.dll as fr.dll (make a copy, rename the copy fr.dll)
|
||||
|
||||
NOTE: You now have two resource files (en.dll and en_small.dll). One is designed for small monitors and one for larger ones. Use the appropriate file depending on the size monitor you plan to use.
|
||||
|
||||
|
||||
2. Copy Localize_template.lua as fr.lua (make a copy, rename the copy fr.lua)
|
||||
|
||||
3. Use a resource editor (search the Internet for an appropriate tool) and edit fr.dll, changing menus, dialogs, and string resources to have the appropriate translations.
|
||||
|
||||
An alternative is to download the Visual Studio project which built the resources file, change that with an appropriate tool (eg. Visual Studio) and recompile to build a new DLL from scratch.
|
||||
|
||||
4. Use a text editor (such as Crimson Editor) to edit the fr.lua file, translating the "empty" strings for each message, into French. Read the forum posting mentioned above for how to handle the "formatted" part.
|
||||
|
||||
You can get Crimson Editor from:
|
||||
|
||||
http://www.crimsoneditor.com/
|
||||
|
||||
Make sure you set the Document Encoding type to UTF-8 (w/o BOM).
|
||||
|
||||
----
|
||||
|
||||
To test, change the locale code in the MUSHclient Global Preferences -> General tab, to "FR".
|
||||
|
||||
Then close and re-open MUSHclient. It should now detect the new files and show the translated messages.
|
||||
|
||||
|
||||
|
||||
Counting translation usage
|
||||
--------------------------
|
||||
|
||||
As there are around 750 messages to be translated in the Localize_template.lua file, you may prefer to concentrate on the ones that occur most frequently.
|
||||
|
||||
To find out what they are, edit your xx.lua file (eg. fr.lua) and add this line to the bottom:
|
||||
|
||||
dofile "locale/count_locale_usage.lua"
|
||||
|
||||
This adds the extra debugging code into your local file. Then, after you have been using MUSHclient for a while, you can enter the following script command:
|
||||
|
||||
/TranslateDebug ()
|
||||
|
||||
This will display which messages were called upon to be translated, sorted into most frequent first, to least frequent.
|
||||
|
||||
|
||||
|
||||
Checking if new messages appear
|
||||
-------------------------------
|
||||
|
||||
With each new release of MUSHclient, you can check if new messages have been added to the file Localize_template.lua by running the Lua script detect_locale_changes.lua. This compares the messages in your locale file (eg. en.lua) to the new template file (ie. Localize_template.lua) and reports on any new ones.
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user