util.encodings: Spell out all IDNA 2008 options ICU has
[prosody.git] / plugins / muc / language.lib.lua
blob2ee2ba0f900840a3bd5c810e925c9bc706a3ed4d
1 -- Prosody IM
2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
4 -- Copyright (C) 2014 Daurnimator
5 --
6 -- This project is MIT/X11 licensed. Please see the
7 -- COPYING file in the source package for more information.
8 --
10 local function get_language(room)
11 return room._data.language;
12 end
14 local function set_language(room, language)
15 if language == "" then language = nil; end
16 if get_language(room) == language then return false; end
17 room._data.language = language;
18 return true;
19 end
21 local function add_disco_form(event)
22 table.insert(event.form, {
23 name = "muc#roominfo_lang";
24 value = "";
25 });
26 event.formdata["muc#roominfo_lang"] = get_language(event.room);
27 end
29 local function add_form_option(event)
30 table.insert(event.form, {
31 name = "muc#roomconfig_lang";
32 label = "Language tag for room (e.g. 'en', 'de', 'fr' etc.)";
33 type = "text-single";
34 desc = "Indicate the primary language spoken in this room";
35 datatype = "xs:language";
36 value = get_language(event.room) or "";
37 });
38 end
40 module:hook("muc-disco#info", add_disco_form);
41 module:hook("muc-config-form", add_form_option, 100-3);
43 module:hook("muc-config-submitted/muc#roomconfig_lang", function(event)
44 if set_language(event.room, event.value) then
45 event.status_codes["104"] = true;
46 end
47 end);
49 return {
50 get = get_language;
51 set = set_language;