Module:Sandbox/BrandonXLF/2
Appearance
-- Sandbox, do not delete
-- Module:Time/js-utils
-- Get all possible JavaScript strings for a language, defaulting to the default message language
local function get_strings(lang_arg)
local lang = lang_arg and mw.getLanguage(lang_arg) or mw.message.getDefaultLanguage();
local digit_str = lang:formatNum(1234567890, {noCommafy = true})
local function msg(key)
return mw.message.new(key):inLanguage(lang):plain()
end
return {
wd = { -- Weekdays
msg('sunday'),
msg('monday'),
msg('tuesday'),
msg('wednesday'),
msg('thursday'),
msg('friday'),
msg('saturday'),
},
wd_a = { -- Weekdays abbreviated
msg('sun'),
msg('mon'),
msg('tue'),
msg('wed'),
msg('thu'),
msg('fri'),
msg('sat'),
},
m = { -- Months
msg('january'),
msg('february'),
msg('march'),
msg('april'),
msg('may_long'),
msg('june'),
msg('july'),
msg('august'),
msg('september'),
msg('october'),
msg('november'),
msg('december'),
},
m_g = { -- Months genitive
msg('january-gen'),
msg('february-gen'),
msg('march-gen'),
msg('april-gen'),
msg('may-gen'),
msg('june-gen'),
msg('july-gen'),
msg('august-gen'),
msg('september-gen'),
msg('october-gen'),
msg('november-gen'),
msg('december-gen'),
},
m_a = { -- Months abbreviated
msg('jan'),
msg('feb'),
msg('mar'),
msg('apr'),
msg('may'),
msg('jun'),
msg('jul'),
msg('aug'),
msg('sep'),
msg('oct'),
msg('nov'),
msg('dec'),
},
di = digit_str ~= "1234567890" -- Digits
and {
['1'] = mw.ustring.sub(digit_str, 1, 1),
['2'] = mw.ustring.sub(digit_str, 2, 2),
['3'] = mw.ustring.sub(digit_str, 3, 3),
['4'] = mw.ustring.sub(digit_str, 4, 4),
['5'] = mw.ustring.sub(digit_str, 5, 5),
['6'] = mw.ustring.sub(digit_str, 6, 6),
['7'] = mw.ustring.sub(digit_str, 7, 7),
['8'] = mw.ustring.sub(digit_str, 8, 8),
['9'] = mw.ustring.sub(digit_str, 9, 9),
['0'] = mw.ustring.sub(digit_str, 10, 10)
}
or nil -- Use default browser digits (0-9)
}
end
-- Keep only the strings that could possibly be required by the format string
-- Might return false positives, but that's ok since the strings will simply be unused
local function possible_strings(strings, fmt)
local required_strs = {
di = strings.di
};
if fmt:find('M', 1, true)
then required_strs.m_a = strings.m_a
end
if fmt:find('F', 1, true)
then required_strs.m = strings.m
end
if fmt:find('xg', 1, true)
then required_strs.m_g = strings.m_g
end
if fmt:find('D', 1, true)
then required_strs.wd_a = strings.wd_a
end
if fmt:find('l', 1, true)
then required_strs.wd = strings.wd
end
return required_strs
end
return {
get_strings = get_strings,
possible_strings = possible_strings,
}