1 [[PageOutline(2-5, Table of Contents, floated)]]
4 This document describes new features and incompatibilities to LuCI 0.9.x.
5 It is targeted at module authors developing external addons to LuCI.
11 The call conventions for the i18n api changed, there is no dedicated translation
12 key anymore and the english text is used for lookup instead. This was done to
13 ease the maintenance of language files.
15 Code that uses _translate()'' or ''i18n()_ must be changed as follows:
19 translate("some_text", "Some Text")
20 translatef("some_format_text", "Some formatted Text: %d", 123)
23 translate("Some Text")
24 translatef("Some formatted Text: %d", 123)
27 Likewise for templates:
31 <%:some_text Some Text%>
37 If code must support both LuCI 0.9.x and 0.10.x versions, it is suggested to write the calls as follows:
39 translate("Some Text", "Some Text")
42 An alternative is wrapping translate() calls into a helper function:
45 return translate(key) or translate(alt) or alt
49 ... which is used as follows:
51 tr("some_key", "Some Text")
54 ## Translation File Format
56 Translation catalogs are now maintained in *.po format files. During build those get translated
57 into [*.lmo archives](http://luci.subsignal.org/trac/wiki/Documentation/LMO).
59 LuCI ships a [utility script](http://luci.subsignal.org/trac/browser/luci/branches/luci-0.10/build/i18n-lua2po.pl)
60 in the build/ directory to convert old Lua translation files to the *.po format. The generated *.po files should
61 be placed in the appropriate subdirectories within the top po/ file in the LuCI source tree.
63 ### Components built within the LuCI tree
65 If components using translations are built along with the LuCI tree, the newly added *.po file are automatically
66 compiled into *.lmo archives during the build process. In order to bundle the appropriate *.lmo files into the
67 corresponding *.ipk packages, component Makefiles must include a "PO" variable specifying the files to include.
69 Given a module _applications/example/'' which uses ''po/en/example.po'' and ''po/en/example-extra.po_,
70 the _applications/example/Makefile_ must be changed as follows:
73 PO = example example-extra
75 include ../../build/config.mk
76 include ../../build/module.mk
79 ### Standalone components
81 Authors who externally package LuCI components must prepare required *.lmo archives themselves.
82 To convert existing Lua based message catalogs to the *.po format, the build/i18n-lua2po.pl helper script can be used.
83 In order to convert *.po files into *.lmo files, the standalone "po2lmo" utility must be compiled as follows:
86 $ svn co http://svn.luci.subsignal.org/luci/branches/luci-0.10/libs/lmo
89 $ ./src/po2lmo translations.po translations.lmo
92 Note that at the time of writing, the utility program needs Lua headers installed on the system in order to compile properly.
98 The server side UVL validation has been dropped to reduce space requirements on the target.
99 Instead it is possible to define datatypes for CBI widgets now:
102 opt = section:option(Value, "optname", "Title Text")
103 opt.datatype = "ip4addr"
106 User provided data is validated once on the frontend via JavaScript and on the server side prior to saving it.
107 A list of possible datatypes can be found in the [luci.cbi.datatypes](http://luci.subsignal.org/trac/browser/luci/branches/luci-0.10/libs/web/luasrc/cbi/datatypes.lua#L26) class.
111 Server-sided validator function can now return custom error messages to provide better feedback on invalid input.
114 opt = section:option(Value, "optname", "Title Text")
116 function opt.validate(self, value, section)
117 if input_is_valid(value) then
120 return nil, "The value is invalid because ..."
127 It is now possible to break up CBI sections into multiple tabs to better organize longer forms.
128 The TypedSection and NamedSection classes gained two new functions to define tabs, _tab()'' and ''taboption()_.
131 sct = map:section(TypedSection, "name", "type", "Title Text")
133 sct:tab("general", "General Tab Title", "General Tab Description")
134 sct:tab("advanced", "Advanced Tab Title", "Advanced Tab Description")
136 opt = sct:taboption("general", Value, "optname", "Title Text")
140 The _tab()_ function is declares a new tab and takes up to three arguments:
141 * Internal name of the tab, must be unique within the section
142 * Title text of the tab
143 * Optional description text for the tab
145 The _taboption()'' function wraps ''option()_ and assigns the option object to the given tab.
146 It takes up to five arguments:
148 * Name of the tab to assign the option to
149 * Option type, e.g. Value or DynamicList
151 * Title text of the option
152 * Optional description text of the option
154 If tabs are used within a particular section, the _option()_ function must not be used,
155 doing so results in undefined behaviour.
159 The CBI gained support for _hooks_ which can be used to trigger additional actions during the
163 map = Map("config", "Title Text")
165 function map.on_commit(self)
166 -- do something if the UCI configuration got committed
170 The following hooks are defined:
172 || on_cancel || The user pressed cancel within a multi-step Delegator or a SimpleForm instance ||
173 || on_init || The CBI is about to render the Map object ||
174 || on_parse || The CBI is about to read received HTTP form values ||
175 || on_save, on_before_save || The CBI is about to save modified UCI configuration files ||
176 || on_after_save || Modified UCI configuration files just got saved
177 || on_before_commit || The CBI is about to commit the changes ||
178 || on_commit, on_after_commit, on_before_apply || Modified configurations got committed and the CBI is about to restart associated services ||
179 || on_apply, on_after_apply || All changes where completely applied (only works on Map instances with the apply_on_parse attribute set) ||
183 TypedSection instances which use the "cbi/tblsection" template may now use a new attribute _sortable_ to allow the user to reorder table rows.
186 sct = map:section(TypedSection, "name", "type", "Title Text")
187 sct.template = "cbi/tblsection"
195 The LuCI 0.10 branch introduced a new JavaScript file _xhr.js_ which provides support routines for XMLHttpRequest operations.
196 Each theme must include this file in the <head> area of the document for forms to work correctly.
198 It should be included like this:
201 <script type="text/javascript" src="<%=resource%>/xhr.js"></script>