webmcp
diff framework/env/__init.lua @ 324:1c3ba14bd679
Root __init.lua function must not set global variables without _G now; Documentation for "_" function added
author | jbe |
---|---|
date | Mon Mar 23 22:41:40 2015 +0100 (2015-03-23) |
parents | 1fbdccf4f8e9 |
children | 3384306aa7bc |
line diff
1.1 --- a/framework/env/__init.lua Mon Mar 23 22:17:33 2015 +0100 1.2 +++ b/framework/env/__init.lua Mon Mar 23 22:41:40 2015 +0100 1.3 @@ -1,5 +1,19 @@ 1.4 --- string localization function 1.5 -function _(text, replacements) 1.6 +--[[-- 1.7 +translated_string = -- translated string 1.8 +_( 1.9 + string_to_translate, -- string to translate 1.10 + { 1.11 + placeholder_name1 = text1, -- replace all occurrences of "#{placeholder_name1}" with the string text1 1.12 + placeholder_name2 = text2, -- replace all occurrences of "#{placeholder_name2}" with the string text2 1.13 + ... 1.14 + } 1.15 +) 1.16 + 1.17 +Translation function for internationalization. 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. 1.18 + 1.19 +--]]-- 1.20 + 1.21 +function _G._(text, replacements) 1.22 local text = locale._get_translation_table()[text] or text 1.23 if replacements then 1.24 return ( 1.25 @@ -15,6 +29,7 @@ 1.26 return text 1.27 end 1.28 end 1.29 +--//-- 1.30 1.31 --[[-- 1.32 cloned_table = -- newly generated table 1.33 @@ -38,11 +53,11 @@ 1.34 --//-- 1.35 1.36 -- load libraries (except "multirand", which must be loaded after forking) 1.37 -extos = require 'extos' 1.38 -nihil = require 'nihil' 1.39 -mondelefant = require 'mondelefant' 1.40 -atom = require 'atom' 1.41 -json = require 'json' 1.42 +_G.extos = require 'extos' 1.43 +_G.nihil = require 'nihil' 1.44 +_G.mondelefant = require 'mondelefant' 1.45 +_G.atom = require 'atom' 1.46 +_G.json = require 'json' 1.47 require 'mondelefant_atom_connector' 1.48 -- NOTE: "multirand" library is loaded in mcp.lua after forking 1.49 1.50 @@ -67,6 +82,6 @@ 1.51 1.52 'config' is a global table, which can be modified by a config file of an application to modify the behaviour of that application. 1.53 --]]-- 1.54 -config = {} 1.55 +_G.config = {} 1.56 --//-- 1.57