Class ::xowiki::formfield::localized_text (public)
::xotcl::Class ::xowiki::formfield::localized_text
Defined in /var/www/openacs.org/packages/xowiki/tcl/form-field-procs.tcl
This class can be used to provide an interface for specifying internationalized text strings saved in message keys via input from a form. When editing the content provided via the input field is saved together with an item-specific message keys in the message key tables via lang::util::convert_to_i18n. This formfield class is especially useful for xowiki items which have no language-prefix (e.g. folders or links). In other cases it is probably still a better idea to create same named pages with different language prefixes.
- See Also:
- Testcases:
- No testcase defined.
Source code: namespace eval ::xowiki::formfield {} ::nsf::object::alloc ::xotcl::Class ::xowiki::formfield::localized_text {set :__default_metaclass ::xotcl::Class set :__default_superclass ::xotcl::Object} ::xowiki::formfield::localized_text instproc escape_message_keys value { # # Do NOT escape message keys (i.e. let them be rendered localized) # return $value } ::xowiki::formfield::localized_text instproc build_message_key_name {-object_id:integer value} { # # Construct a per-item message key for this formfield # return xowiki-$object_id-formfield-${:name} } ::xowiki::formfield::localized_text instproc pretty_value v { # # Convert message keys to text so that e.g. wikicmds are # afterwards evaluated. # set locale [[${:object} package_id] default_locale] return [lang::util::localize $v $locale] } ::xowiki::formfield::localized_text instproc convert_to_internal {} { set value [:value] # # When the provided values does not look like a message key, then # create a new one on the fly. # #:log "localized_text sees <$value>" if {![regexp [lang::util::message_key_regexp] $value]} { set object_id [${:object} item_id] set package_id [${:object} package_id] # # Try to get the desired locale first from a form parameter with # a name suffix "__locale" or get the locale as specified by the user. # set locale [::$package_id form_parameter "${:name}__locale:token" [::$package_id default_locale]] # # Save the value in the message keys with the resulting locale # set value [lang::util::convert_to_i18n -locale $locale -object_id $object_id -message_key [:build_message_key_name -object_id $object_id ${:name}] -text $value] ${:object} set_property -new 1 ${:name} $value } } ::xowiki::formfield::localized_text instproc render_input {} { # # Rely on the superclass to do the right rendering of the main # content widget. # next # # Add a small selector for specifying the locale for the provided # message string. # set value [[${:object} package_id] default_locale] set :localizer_class locale-selector set :localizer_id ${:id}__locale set :localizer_name ${:name}__locale set atts [:get_attributes disabled {localizer_class class} {localizer_id id} {localizer_name name}] ::html::select $atts { foreach o [xowiki::locales] { lassign $o label rep set atts [list value $rep] if {$rep in $value} { lappend atts selected selected } ::html::option $atts {::html::t $label} } } } ::nsf::relation::set ::xowiki::formfield::localized_text superclass ::xowiki::formfield::textXQL Not present: Generic, PostgreSQL, Oracle