webmcp
view framework/env/locale/do_with.lua @ 561:e13a3fa97aad
Removed unused pointer for database connection to avoid compiler warning
| author | jbe | 
|---|---|
| date | Fri Feb 05 15:37:48 2021 +0100 (2021-02-05) | 
| parents | c3d539e33710 | 
| children | 
 line source
     1 --[[--
     2 locale.do_with(
     3   locale_options,  -- table with locale information (as if passed to locale.set(...))
     4   function()
     5     ...            -- code to be executed with the given locale settings
     6   end
     7 )
     9 This function executes code with temporarily changed locale settings. See locale.set(...) for correct usage of 'locale_options'.
    11 --]]--
    13 function locale.do_with(locale_options, block)
    14   local old_data = table.new(locale._current_data)
    15   if locale_options.reset then
    16     locale._current_data = {}
    17   end
    18   for key, value in pairs(locale_options) do
    19     if key ~= "reset" then
    20       locale._current_data[key] = value
    21     end
    22   end
    23   locale.set(locale_options)
    24   block()
    25   locale._current_data = old_data
    26 end
