diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/events.lua | 6 | ||||
-rw-r--r-- | core/file_io.lua | 30 | ||||
-rw-r--r-- | core/gui.lua | 42 | ||||
-rw-r--r-- | core/init.lua | 3 | ||||
-rw-r--r-- | core/keys.lua | 8 | ||||
-rw-r--r-- | core/locale.lua | 26 |
6 files changed, 46 insertions, 69 deletions
diff --git a/core/events.lua b/core/events.lua index 87861fca..fed85a72 100644 --- a/core/events.lua +++ b/core/events.lua @@ -1,7 +1,5 @@ -- Copyright 2007-2011 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local L = locale.localize - local M = {} --[[ This comment is for LuaDoc. @@ -196,7 +194,7 @@ M.handlers = {} -- @see disconnect -- @name connect function M.connect(event, f, index) - if not event then error(L('Undefined event name')) end + if not event then error(_L['Undefined event name']) end if not M.handlers[event] then M.handlers[event] = {} end local h = M.handlers[event] if index then table.insert(h, index, f) else h[#h + 1] = f end @@ -227,7 +225,7 @@ local error_emitted = false -- otherwise. -- @name emit function M.emit(event, ...) - if not event then error(L('Undefined event name')) end + if not event then error(_L['Undefined event name']) end local h = M.handlers[event] if not h then return end local pcall, table_unpack, type = pcall, table.unpack, type diff --git a/core/file_io.lua b/core/file_io.lua index b2e02ead..82ddd73d 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -1,8 +1,5 @@ -- Copyright 2007-2011 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local L = locale.localize -local events = events - --[[ This comment is for LuaDoc. --- -- Extends Lua's io package to provide file input/output routines for Textadept. @@ -44,6 +41,7 @@ module('io')]] -- * `filename`: The filename encoded in UTF-8. -- Events. +local events = events events.FILE_OPENED = 'file_opened' events.FILE_BEFORE_SAVE = 'file_before_save' events.FILE_AFTER_SAVE = 'file_after_save' @@ -106,7 +104,7 @@ io.try_encodings = { 'UTF-8', 'ASCII', 'ISO-8859-1', 'MacRoman' } function io.open_file(utf8_filenames) utf8_filenames = utf8_filenames or gui.dialog('fileselect', - '--title', L('Open'), + '--title', _L['Open'], '--select-multiple', '--with-directory', (buffer.filename or ''):match('.+[/\\]') or '') @@ -136,7 +134,7 @@ function io.open_file(utf8_filenames) local ok, conv = pcall(string.iconv, text, 'UTF-8', try_encoding) if ok then encoding, text = try_encoding, conv break end end - if not encoding then error(L('Encoding conversion failed.')) end + if not encoding then error(_L['Encoding conversion failed.']) end end else encoding = nil @@ -193,7 +191,9 @@ end -- LuaDoc is in core/.buffer.luadoc. local function set_encoding(buffer, encoding) buffer:check_global() - if not buffer.encoding then error(L('Cannot change binary file encoding')) end + if not buffer.encoding then + error(_L['Cannot change binary file encoding']) + end local pos, first_visible_line = buffer.current_pos, buffer.first_visible_line local text = buffer:get_text(buffer.length) text = text:iconv(buffer.encoding, 'UTF-8') @@ -233,7 +233,7 @@ local function save_as(buffer, utf8_filename) buffer:check_global() if not utf8_filename then utf8_filename = gui.dialog('filesave', - '--title', L('Save'), + '--title', _L['Save'], '--with-directory', (buffer.filename or ''):match('.+[/\\]') or '', '--with-file', @@ -265,13 +265,13 @@ end local function close(buffer) if not buffer then buffer = _G.buffer end buffer:check_global() - local filename = buffer.filename or buffer._type or L('Untitled') + local filename = buffer.filename or buffer._type or _L['Untitled'] if buffer.dirty and gui.dialog('msgbox', - '--title', L('Close without saving?'), - '--text', L('There are unsaved changes in'), + '--title', _L['Close without saving?'], + '--text', _L['There are unsaved changes in'], '--informative-text', filename, '--button1', 'gtk-cancel', - '--button2', L('Close _without saving'), + '--button2', _L['Close _without saving'], '--no-newline') ~= '2' then return false end @@ -306,11 +306,11 @@ local function update_modified_file() if buffer.modification_time < attributes.modification then buffer.modification_time = attributes.modification if gui.dialog('yesno-msgbox', - '--title', L('Reload?'), - '--text', L('Reload modified file?'), + '--title', _L['Reload?'], + '--text', _L['Reload modified file?'], '--informative-text', ('"%s"\n%s'):format(utf8_filename, - L('has been modified. Reload it?')), + _L['has been modified. Reload it?']), '--no-cancel', '--no-newline') == '1' then buffer:reload() @@ -342,6 +342,6 @@ end) -- Prompts the user to open a recently opened file. -- @name open_recent_file function io.open_recent_file() - local i = gui.filteredlist(L('Open'), L('File'), io.recent_files, true) + local i = gui.filteredlist(_L['Open'], _L['File'], io.recent_files, true) if i then io.open_file(io.recent_files[i + 1]) end end diff --git a/core/gui.lua b/core/gui.lua index c4461561..349c0dbb 100644 --- a/core/gui.lua +++ b/core/gui.lua @@ -1,6 +1,5 @@ -- Copyright 2007-2011 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local L = locale.localize local gui = gui --[[ This comment is for LuaDoc. @@ -19,6 +18,8 @@ module('gui')]] -- (Write-only) -- * `size` [table]: The size of the Textadept window (`{ width, height }`). +local _L = _L + -- Helper function for printing messages to buffers. -- @see gui._print local function _print(buffer_type, ...) @@ -52,8 +53,8 @@ end -- buffer, and prints to it. -- @param buffer_type String type of message buffer. -- @param ... Message strings. --- @usage gui._print(L('[Error Buffer]'), error_message) --- @usage gui._print(L('[Message Buffer]'), message) +-- @usage gui._print(_L['[Error Buffer]'], error_message) +-- @usage gui._print(_L['[Message Buffer]'], message) -- @name _print function gui._print(buffer_type, ...) pcall(_print, buffer_type, ...) end @@ -63,7 +64,7 @@ function gui._print(buffer_type, ...) pcall(_print, buffer_type, ...) end -- messages. -- @param ... Message strings. -- @name print -function gui.print(...) gui._print(L('[Message Buffer]'), ...) end +function gui.print(...) gui._print(_L['[Message Buffer]'], ...) end --- -- Shortcut function for `gui.dialog('filtered_list', ...)` with 'Ok' and @@ -102,13 +103,13 @@ end -- selected one, if any. -- @name switch_buffer function gui.switch_buffer() - local columns, items = { L('Name'), L('File') }, {} + local columns, items = { _L['Name'], _L['File'] }, {} for _, buffer in ipairs(_BUFFERS) do - local filename = buffer.filename or buffer._type or L('Untitled') + local filename = buffer.filename or buffer._type or _L['Untitled'] items[#items + 1] = (buffer.dirty and '*' or '')..filename:match('[^/\\]+$') items[#items + 1] = filename end - local i = gui.filteredlist(L('Switch Buffers'), columns, items, true) + local i = gui.filteredlist(_L['Switch Buffers'], columns, items, true) if i then view:goto_buffer(i + 1) end end @@ -170,7 +171,7 @@ function gui.set_theme(name) elseif lfs.attributes(name) then theme = name end - if not theme then error(('"%s" %s'):format(name, L("theme not found."))) end + if not theme then error(('"%s" %s'):format(name, _L["theme not found."])) end if buffer and view then local current_buffer, current_view = _BUFFERS[buffer], _VIEWS[view] @@ -212,7 +213,7 @@ function gui.select_theme() end for theme in pairs(themes_found) do themes[#themes + 1] = theme end table.sort(themes) - local theme = gui.filteredlist(L('Select Theme'), L('Name'), themes) + local theme = gui.filteredlist(_L['Select Theme'], _L['Name'], themes) if not theme then return end gui.set_theme(theme) local f = io.open(_USERHOME..'/theme', 'wb') @@ -280,7 +281,7 @@ end) -- Sets the title of the Textadept window to the buffer's filename. -- @param buffer The global buffer. local function set_title(buffer) - local filename = buffer.filename or buffer._type or L('Untitled') + local filename = buffer.filename or buffer._type or _L['Untitled'] gui.title = string.format('%s %s Textadept (%s)', filename:match('[^/\\]+$'), buffer.dirty and '*' or '-', filename) end @@ -316,7 +317,7 @@ connect(events.APPLEEVENT_ODOC, function(uri) end) local string_format = string.format -local EOLs = { L('CRLF'), L('CR'), L('LF') } +local EOLs = { _L['CRLF'], _L['CR'], _L['LF'] } local GETLEXERLANGUAGE = _SCINTILLA.functions.get_lexer_language[1] -- Sets docstatusbar text. connect(events.UPDATE_UI, function() @@ -326,12 +327,12 @@ connect(events.UPDATE_UI, function() local col = buffer.column[pos] + 1 local lexer = buffer:private_lexer_call(GETLEXERLANGUAGE) local eol = EOLs[buffer.eol_mode + 1] - local tabs = string_format('%s %d', buffer.use_tabs and L('Tabs:') or - L('Spaces:'), buffer.indent) + local tabs = string_format('%s %d', buffer.use_tabs and _L['Tabs:'] or + _L['Spaces:'], buffer.indent) local enc = buffer.encoding or '' gui.docstatusbar_text = - string_format('%s %d/%d %s %d %s %s %s %s', L('Line:'), line, - max, L('Col:'), col, lexer, eol, tabs, enc) + string_format('%s %d/%d %s %d %s %s %s %s', _L['Line:'], + line, max, _L['Col:'], col, lexer, eol, tabs, enc) end) -- Toggles folding. @@ -391,22 +392,23 @@ connect(events.QUIT, function() local list = {} for _, buffer in ipairs(_BUFFERS) do if buffer.dirty then - list[#list + 1] = buffer.filename or buffer._type or L('Untitled') + list[#list + 1] = buffer.filename or buffer._type or _L['Untitled'] end end if #list > 0 and gui.dialog('msgbox', - '--title', L('Quit without saving?'), - '--text', L('The following buffers are unsaved:'), + '--title', _L['Quit without saving?'], + '--text', + _L['The following buffers are unsaved:'], '--informative-text', table.concat(list, '\n'), '--button1', 'gtk-cancel', - '--button2', L('Quit _without saving'), + '--button2', _L['Quit _without saving'], '--no-newline') ~= '2' then return false end return true end) -connect(events.ERROR, function(...) gui._print(L('[Error Buffer]'), ...) end) +connect(events.ERROR, function(...) gui._print(_L['[Error Buffer]'], ...) end) --[[ The functions below are Lua C functions. diff --git a/core/init.lua b/core/init.lua index 5543cf99..93746589 100644 --- a/core/init.lua +++ b/core/init.lua @@ -8,7 +8,7 @@ os.setlocale('C', 'collate') if jit then require 'compat' end -- compatibility for LuaJIT _SCINTILLA = require 'iface' args = require 'args' -locale = require 'locale' +_L = require 'locale' events = require 'events' require 'file_io' require 'gui' @@ -34,6 +34,7 @@ module('_G')]] -- * `_USERHOME` [string]: Path to the user's `~/.textadept/`. -- * `_CHARSET` [string]: The character set encoding of the filesystem. This is -- used in [File I/O](../modules/io.html). +-- * `_L` [table]: Contains all messages used by Textadept for localization. -- * `RESETTING` [bool]: If [`reset()`](../modules/_G.html#reset) has been -- called, this flag is `true` while the Lua state is being re-initialized. -- * `WIN32` [bool]: If Textadept is running on Windows, this flag is `true`. diff --git a/core/keys.lua b/core/keys.lua index 9a186eed..e02b0454 100644 --- a/core/keys.lua +++ b/core/keys.lua @@ -1,7 +1,5 @@ -- Copyright 2007-2011 Mitchell mitchell<att>caladbolg.net. See LICENSE. -local L = locale.localize - local M = {} --[[ This comment is for LuaDoc. @@ -188,7 +186,7 @@ local function run_key_command(lexer) if key_type ~= 'function' and key_type ~= 'table' then return INVALID end if key_type == 'table' and #key == 0 and next(key) then - gui.statusbar_text = L('Keychain:')..' '..table.concat(keychain, ' ') + gui.statusbar_text = _L['Keychain:']..' '..table.concat(keychain, ' ') return CHAIN end @@ -234,7 +232,7 @@ local function keypress(code, shift, control, alt, meta) -- command itself. keychain = {} local text = gui.statusbar_text or '' - if text == L('Invalid sequence') or text:find('^'..L('Keychain:')) then + if text == _L['Invalid sequence'] or text:find(_L['Keychain:']) then gui.statusbar_text = '' end end @@ -245,7 +243,7 @@ local function keypress(code, shift, control, alt, meta) local size = #keychain - 1 clear_key_sequence() if not success and size > 0 then -- INVALID keychain sequence - gui.statusbar_text = L('Invalid sequence') + gui.statusbar_text = _L['Invalid sequence'] return true end -- PROPAGATE otherwise. diff --git a/core/locale.lua b/core/locale.lua index 3975c323..1ba3a8f1 100644 --- a/core/locale.lua +++ b/core/locale.lua @@ -2,37 +2,15 @@ local M = {} ---[[ This comment is for LuaDoc. ---- --- Contains all messages used by Textadept for localization. -module('locale')]] - --- Markdown: --- ## Fields --- --- Each message ID in `core/locale.conf` is accessible as a field in this --- module. - --- Contains all localizations for the current locale. --- @class table --- @name localizations -local localizations = {} - local f = io.open(_USERHOME..'/locale.conf', 'rb') if not f then f = io.open(_HOME..'/core/locale.conf', 'rb') end if not f then error('"core/locale.conf" not found.') end for line in f:lines() do if not line:find('^%s*%%') then local id, str = line:match('^(.-)%s*=%s*(.+)$') - if id and str then localizations[id] = str end + if id and str then M[id] = str end end end f:close() ---- --- Localizes the given string. --- @param id String to localize. --- @name localize -function M.localize(id) return localizations[id] or 'No Localization' end - -return M +return setmetatable(M, { __index = function() return 'No Localization' end }) |