webmcp
diff framework/env/locale/do_with.lua @ 0:9fdfb27f8e67
Version 1.0.0
author | jbe/bsw |
---|---|
date | Sun Oct 25 12:00:00 2009 +0100 (2009-10-25) |
parents | |
children | c3d539e33710 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/framework/env/locale/do_with.lua Sun Oct 25 12:00:00 2009 +0100 1.3 @@ -0,0 +1,22 @@ 1.4 +--[[-- 1.5 +locale.do_with( 1.6 + locale_options, -- table with locale information (as if passed to locale.set(...)) 1.7 + function() 1.8 + ... -- code to be executed with the given locale settings 1.9 + end 1.10 +) 1.11 + 1.12 +This function executes code with temporarily changed locale settings. See locale.set(...) for correct usage of 'locale_options'. 1.13 + 1.14 +--]]-- 1.15 + 1.16 +function locale.do_with(locale_options, block) 1.17 + local old_data = {} 1.18 + for key, value in pairs(locale._current_data) do 1.19 + old_data[key] = value 1.20 + end 1.21 + locale.set(locale_options) 1.22 + block() 1.23 + old_data.reset = true 1.24 + locale.set(old_data) 1.25 +end