webmcp

view framework/env/__init.lua @ 569:5b19007574de

New argument active_link_attr for env.ui.paginate{...}
author jbe
date Wed Oct 13 17:21:44 2021 +0200 (2021-10-13)
parents 2c31275322db
children
line source
1 --[[--
2 translated_string = -- translated string
3 _(
4 string_to_translate, -- string to translate
5 {
6 placeholder_name1 = text1, -- replace all occurrences of "#{placeholder_name1}" with the string text1
7 placeholder_name2 = text2, -- replace all occurrences of "#{placeholder_name2}" with the string text2
8 ...
9 }
10 )
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.
14 Hint: Lua's syntax rules allow to write _"text" as a shortcut for _("text"), or _'text' instead of _('text') respectivly.
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 = ...}.
17 The special string "__parent" in the translation file may point to a different language code of which all translations are inherited from.
19 --]]--
21 function _G._(text, replacements)
22 local text = locale._get_translation_table()[text] or text
23 if replacements then
24 return (
25 string.gsub(
26 text,
27 "#{(.-)}",
28 function (placeholder)
29 return replacements[placeholder]
30 end
31 )
32 )
33 else
34 return text
35 end
36 end
37 --//--
39 --[[--
40 cloned_table = -- newly generated table
41 table.new(
42 table_or_nil -- keys of a given table will be copied to the new table
43 )
45 If a table is given, then a cloned table is returned.
46 If nil is given, then a new empty table is returned.
48 --]]--
49 function table.new(tbl)
50 local new_tbl = {}
51 if tbl then
52 for key, value in pairs(tbl) do
53 new_tbl[key] = value
54 end
55 end
56 return new_tbl
57 end
58 --//--
60 --[[--
61 table.insert(
62 t, -- table
63 index, -- optional index
64 value -- value
65 )
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).
69 --]]--
70 if _VERSION == "Lua 5.2" then
71 local old_insert = table.insert
72 function table.insert(...)
73 if select("#", ...) == 2 then
74 local t, value = ...
75 t[#t+1] = value
76 return
77 end
78 return old_insert(...)
79 end
80 end
81 --//--
83 -- load libraries
84 -- (except "extos", which has to be loaded earlier, and "multirand", which must be loaded after forking)
85 _G.nihil = require 'nihil'
86 _G.mondelefant = require 'mondelefant'
87 _G.atom = require 'atom'
88 _G.json = require 'json'
89 require 'mondelefant_atom_connector'
90 -- NOTE: "multirand" library is loaded in mcp.lua after forking
92 -- setup mondelefant
93 mondelefant.connection_prototype.error_objects = true
94 function mondelefant.connection_prototype:sql_tracer(command)
95 if trace.is_disabled() then
96 return
97 end
98 local start_time = extos.monotonic_hires_time()
99 return function(error_info)
100 trace.sql{
101 command = command,
102 execution_time = extos.monotonic_hires_time() - start_time,
103 error_position = error_info and error_info.position or nil
104 }
105 end
106 end
108 --[[--
109 config -- table to store application configuration
111 'config' is a global table, which can be modified by a config file of an application to modify the behaviour of that application.
112 --]]--
113 _G.config = {}
114 --//--

Impressum / About Us