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@324
|
16 --]]--
|
jbe@324
|
17
|
jbe@324
|
18 function _G._(text, replacements)
|
jbe/bsw@0
|
19 local text = locale._get_translation_table()[text] or text
|
jbe/bsw@0
|
20 if replacements then
|
jbe/bsw@0
|
21 return (
|
jbe/bsw@0
|
22 string.gsub(
|
jbe/bsw@0
|
23 text,
|
jbe/bsw@0
|
24 "#{(.-)}",
|
jbe/bsw@0
|
25 function (placeholder)
|
jbe/bsw@0
|
26 return replacements[placeholder]
|
jbe/bsw@0
|
27 end
|
jbe/bsw@0
|
28 )
|
jbe/bsw@0
|
29 )
|
jbe/bsw@0
|
30 else
|
jbe/bsw@0
|
31 return text
|
jbe/bsw@0
|
32 end
|
jbe/bsw@0
|
33 end
|
jbe@324
|
34 --//--
|
jbe@203
|
35
|
jbe@203
|
36 --[[--
|
jbe@203
|
37 cloned_table = -- newly generated table
|
jbe@203
|
38 table.new(
|
jbe@203
|
39 table_or_nil -- keys of a given table will be copied to the new table
|
jbe@203
|
40 )
|
jbe@203
|
41
|
jbe@203
|
42 If a table is given, then a cloned table is returned.
|
jbe@203
|
43 If nil is given, then a new empty table is returned.
|
jbe@203
|
44
|
jbe@203
|
45 --]]--
|
jbe@203
|
46 function table.new(tbl)
|
jbe@240
|
47 local new_tbl = {}
|
jbe@203
|
48 if tbl then
|
jbe@203
|
49 for key, value in pairs(tbl) do
|
jbe@203
|
50 new_tbl[key] = value
|
jbe@203
|
51 end
|
jbe@203
|
52 end
|
jbe@203
|
53 return new_tbl
|
jbe@203
|
54 end
|
jbe@203
|
55 --//--
|
jbe@203
|
56
|
jbe@352
|
57 -- load libraries
|
jbe@352
|
58 -- (except "extos", which has to be loaded earlier, and "multirand", which must be loaded after forking)
|
jbe@324
|
59 _G.nihil = require 'nihil'
|
jbe@324
|
60 _G.mondelefant = require 'mondelefant'
|
jbe@324
|
61 _G.atom = require 'atom'
|
jbe@324
|
62 _G.json = require 'json'
|
jbe@203
|
63 require 'mondelefant_atom_connector'
|
jbe@286
|
64 -- NOTE: "multirand" library is loaded in mcp.lua after forking
|
jbe@203
|
65
|
jbe@295
|
66 -- setup mondelefant
|
jbe@295
|
67 mondelefant.connection_prototype.error_objects = true
|
jbe@295
|
68 function mondelefant.connection_prototype:sql_tracer(command)
|
jbe@295
|
69 if trace.is_disabled() then
|
jbe@295
|
70 return
|
jbe@295
|
71 end
|
jbe@295
|
72 local start_time = extos.monotonic_hires_time()
|
jbe@295
|
73 return function(error_info)
|
jbe@295
|
74 trace.sql{
|
jbe@295
|
75 command = command,
|
jbe@295
|
76 execution_time = extos.monotonic_hires_time() - start_time,
|
jbe@295
|
77 error_position = error_info and error_info.position or nil
|
jbe@295
|
78 }
|
jbe@295
|
79 end
|
jbe@295
|
80 end
|
jbe@295
|
81
|
jbe@206
|
82 --[[--
|
jbe@206
|
83 config -- table to store application configuration
|
jbe@206
|
84
|
jbe@206
|
85 '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
|
86 --]]--
|
jbe@324
|
87 _G.config = {}
|
jbe@206
|
88 --//--
|
jbe@206
|
89
|