rev |
line source |
jbe@324
|
1 --[[--
|
jbe@324
|
2 translated_string = -- translated string
|
jbe@324
|
3 _(
|
jbe@324
|
4 string_to_translate, -- string to translate
|
jbe@324
|
5 {
|
jbe@324
|
6 placeholder_name1 = text1, -- replace all occurrences of "#{placeholder_name1}" with the string text1
|
jbe@324
|
7 placeholder_name2 = text2, -- replace all occurrences of "#{placeholder_name2}" with the string text2
|
jbe@324
|
8 ...
|
jbe@324
|
9 }
|
jbe@324
|
10 )
|
jbe@324
|
11
|
jbe@325
|
12 Translation function for localization. The "_" function translates a given string to the currently selected language (see locale.set{...}). If the translated string contains placeholders in the form #{name}, then those placeholders may be automatically replaced with a corresponding substring which is taken from the table passed as optional second argument.
|
jbe@325
|
13
|
jbe@325
|
14 Hint: Lua's syntax rules allow to write _"text" as a shortcut for _("text"), or _'text' instead of _('text') respectivly.
|
jbe@324
|
15
|
jbe@563
|
16 Translation files are located in the "locale" directory of the application and must have a name following the schema "translations.LANG.lua", where LANG is the language code set with locale.set{lang = ...}.
|
jbe@563
|
17 The special string "__parent" in the translation file may point to a different language code of which all translations are inherited from.
|
jbe@563
|
18
|
jbe@324
|
19 --]]--
|
jbe@324
|
20
|
jbe@324
|
21 function _G._(text, replacements)
|
jbe/bsw@0
|
22 local text = locale._get_translation_table()[text] or text
|
jbe/bsw@0
|
23 if replacements then
|
jbe/bsw@0
|
24 return (
|
jbe/bsw@0
|
25 string.gsub(
|
jbe/bsw@0
|
26 text,
|
jbe/bsw@0
|
27 "#{(.-)}",
|
jbe/bsw@0
|
28 function (placeholder)
|
jbe/bsw@0
|
29 return replacements[placeholder]
|
jbe/bsw@0
|
30 end
|
jbe/bsw@0
|
31 )
|
jbe/bsw@0
|
32 )
|
jbe/bsw@0
|
33 else
|
jbe/bsw@0
|
34 return text
|
jbe/bsw@0
|
35 end
|
jbe/bsw@0
|
36 end
|
jbe@324
|
37 --//--
|
jbe@203
|
38
|
jbe@203
|
39 --[[--
|
jbe@203
|
40 cloned_table = -- newly generated table
|
jbe@203
|
41 table.new(
|
jbe@203
|
42 table_or_nil -- keys of a given table will be copied to the new table
|
jbe@203
|
43 )
|
jbe@203
|
44
|
jbe@203
|
45 If a table is given, then a cloned table is returned.
|
jbe@203
|
46 If nil is given, then a new empty table is returned.
|
jbe@203
|
47
|
jbe@203
|
48 --]]--
|
jbe@203
|
49 function table.new(tbl)
|
jbe@240
|
50 local new_tbl = {}
|
jbe@203
|
51 if tbl then
|
jbe@203
|
52 for key, value in pairs(tbl) do
|
jbe@203
|
53 new_tbl[key] = value
|
jbe@203
|
54 end
|
jbe@203
|
55 end
|
jbe@203
|
56 return new_tbl
|
jbe@203
|
57 end
|
jbe@203
|
58 --//--
|
jbe@203
|
59
|
jbe@495
|
60 --[[--
|
jbe@495
|
61 table.insert(
|
jbe@495
|
62 t, -- table
|
jbe@495
|
63 index, -- optional index
|
jbe@495
|
64 value -- value
|
jbe@495
|
65 )
|
jbe@495
|
66
|
jbe@495
|
67 Custom implementation of Lua's table.insert(...) where table.insert(table, value) also respects metamethods in Lua 5.2 (this behavior is already supported by Lua 5.3).
|
jbe@495
|
68
|
jbe@495
|
69 --]]--
|
jbe@498
|
70 if _VERSION == "Lua 5.2" then
|
jbe@495
|
71 local old_insert = table.insert
|
jbe@495
|
72 function table.insert(...)
|
jbe@498
|
73 if select("#", ...) == 2 then
|
jbe@495
|
74 local t, value = ...
|
jbe@495
|
75 t[#t+1] = value
|
jbe@495
|
76 return
|
jbe@495
|
77 end
|
jbe@495
|
78 return old_insert(...)
|
jbe@495
|
79 end
|
jbe@495
|
80 end
|
jbe@495
|
81 --//--
|
jbe@495
|
82
|
jbe@352
|
83 -- load libraries
|
jbe@352
|
84 -- (except "extos", which has to be loaded earlier, and "multirand", which must be loaded after forking)
|
jbe@324
|
85 _G.nihil = require 'nihil'
|
jbe@324
|
86 _G.mondelefant = require 'mondelefant'
|
jbe@324
|
87 _G.atom = require 'atom'
|
jbe@324
|
88 _G.json = require 'json'
|
jbe@203
|
89 require 'mondelefant_atom_connector'
|
jbe@286
|
90 -- NOTE: "multirand" library is loaded in mcp.lua after forking
|
jbe@203
|
91
|
jbe@295
|
92 -- setup mondelefant
|
jbe@295
|
93 mondelefant.connection_prototype.error_objects = true
|
jbe@295
|
94 function mondelefant.connection_prototype:sql_tracer(command)
|
jbe@295
|
95 if trace.is_disabled() then
|
jbe@295
|
96 return
|
jbe@295
|
97 end
|
jbe@295
|
98 local start_time = extos.monotonic_hires_time()
|
jbe@295
|
99 return function(error_info)
|
jbe@295
|
100 trace.sql{
|
jbe@295
|
101 command = command,
|
jbe@295
|
102 execution_time = extos.monotonic_hires_time() - start_time,
|
jbe@295
|
103 error_position = error_info and error_info.position or nil
|
jbe@295
|
104 }
|
jbe@295
|
105 end
|
jbe@295
|
106 end
|
jbe@295
|
107
|
jbe@206
|
108 --[[--
|
jbe@206
|
109 config -- table to store application configuration
|
jbe@206
|
110
|
jbe@206
|
111 'config' is a global table, which can be modified by a config file of an application to modify the behaviour of that application.
|
jbe@206
|
112 --]]--
|
jbe@324
|
113 _G.config = {}
|
jbe@206
|
114 --//--
|
jbe@206
|
115
|