From a6db84b985f7143c01e750943ec7a82ec113a233 Mon Sep 17 00:00:00 2001 From: gc Date: Sun, 2 Mar 2008 22:35:40 +0000 Subject: [PATCH] multi languages in booh --- bin/booh | 175 ++++++++++++++++++++++++++++++++++++++++++- bin/booh-backend | 4 +- lib/booh/booh-lib.rb | 7 ++ 3 files changed, 179 insertions(+), 7 deletions(-) diff --git a/bin/booh b/bin/booh index 9376cc2..c9439e8 100755 --- a/bin/booh +++ b/bin/booh @@ -1924,7 +1924,7 @@ def show_popup(parent, msg, *options) linkbut = Gtk::Button.new('') linkbut.child.markup = "#{options[0][:linkurl]}" linkbut.signal_connect('clicked') { - open_url(options[0][:linkurl] + '/index.html') + open_url(options[0][:linkurl]) dialog.response(Gtk::Dialog::RESPONSE_OK) set_mousecursor_normal } @@ -2913,6 +2913,129 @@ def additional_booh_options return options end +def ask_multi_languages(value) + if ! value.nil? + spl = value.split(',') + value = [ spl[0..-2], spl[-1] ] + end + + dialog = Gtk::Dialog.new(utf8(_("Multi-languages support")), + $main_window, + Gtk::Dialog::MODAL, + [Gtk::Stock::OK, Gtk::Dialog::RESPONSE_OK], + [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL]) + + lbl = Gtk::Label.new + lbl.markup = utf8( +_("You can choose to activate multi-languages support for this web-album +(it will work only if you publish your web-album on an Apache web-server). This will +use the MultiViews feature of Apache; the pages will be served according to the +value of the Accept-Language HTTP header sent by the web browsers, so that people +with different languages preferences will be able to browse your web-album with +navigation in their language (if language is available). +")) + + dialog.vbox.add(lbl) + dialog.vbox.add(Gtk::Alignment.new(0.5, 0.5, 0, 0).add(Gtk::VBox.new.add(rb_no = Gtk::RadioButton.new(utf8(_("Disabled")))). + add(Gtk::HBox.new(false, 5).add(rb_yes = Gtk::RadioButton.new(rb_no, utf8(_("Enabled")))). + add(languages = Gtk::Button.new)))) + + pick_languages = proc { + dialog2 = Gtk::Dialog.new(utf8(_("Pick languages to support")), + $main_window, + Gtk::Dialog::MODAL, + [Gtk::Stock::OK, Gtk::Dialog::RESPONSE_OK], + [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL]) + + dialog2.vbox.add(Gtk::Alignment.new(0.5, 0.5, 0, 0).add(hb1 = Gtk::HBox.new)) + hb1.add(Gtk::Label.new(utf8(_("Select the languages to support:")))) + cbs = [] + SUPPORTED_LANGUAGES.each { |lang| + hb1.add(cb = Gtk::CheckButton.new(utf8(langname(lang)))) + if ! value.nil? && value[0].include?(lang) + cb.active = true + end + cbs << [ lang, cb ] + } + + dialog2.vbox.add(Gtk::Alignment.new(0.5, 0.5, 0, 0).add(hb2 = Gtk::HBox.new)) + hb2.add(Gtk::Label.new(utf8(_("Select the fallback language:")))) + fallback_language = nil + hb2.add(fbl_rb = Gtk::RadioButton.new(utf8(langname(SUPPORTED_LANGUAGES[0])))) + fbl_rb.signal_connect('clicked') { fallback_language = SUPPORTED_LANGUAGES[0] } + if value.nil? || value[1] == SUPPORTED_LANGUAGES[0] + fbl_rb.active = true + fallback_language = SUPPORTED_LANGUAGES[0] + end + SUPPORTED_LANGUAGES[1..-1].each { |lang| + hb2.add(rb = Gtk::RadioButton.new(fbl_rb, utf8(langname(lang)))) + rb.signal_connect('clicked') { fallback_language = lang } + if ! value.nil? && value[1] == lang + rb.active = true + end + } + + dialog2.window_position = Gtk::Window::POS_MOUSE + dialog2.show_all + + resp = nil + dialog2.run { |response| + resp = response + if resp == Gtk::Dialog::RESPONSE_OK + value = [] + value[0] = cbs.find_all { |e| e[1].active? }.collect { |e| e[0] } + value[1] = fallback_language + languages.label = utf8(_("Languages: %s. Fallback: %s.") % [ value[0].collect { |v| utf8(langname(v)) }.join(', '), utf8(langname(value[1])) ]) + end + dialog2.destroy + } + resp + } + + languages.signal_connect('clicked') { + pick_languages.call + } + dialog.window_position = Gtk::Window::POS_MOUSE + if value.nil? + rb_no.active = true + else + rb_yes.active = true + languages.label = utf8(_("Languages: %s. Fallback: %s.") % [ value[0].collect { |v| utf8(langname(v)) }.join(', '), utf8(langname(value[1])) ]) + end + rb_no.signal_connect('clicked') { + if rb_no.active? + languages.hide + else + if pick_languages.call == Gtk::Dialog::RESPONSE_CANCEL + rb_no.activate + else + languages.show + end + end + } + oldval = value + dialog.show_all + if rb_no.active? + languages.hide + end + + dialog.run { |response| + if rb_no.active? + value = nil + end + dialog.destroy + if response == Gtk::Dialog::RESPONSE_OK && value != oldval + if value.nil? + return [ true, nil ] + else + return [ true, (value[0].size == 0 ? '' : value[0].join(',') + ',') + value[1] ] + end + else + return [ false ] + end + } +end + def new_album if !ask_save_modifications(utf8(_("Save this album?")), utf8(_("Do you want to save the changes to this album?")), @@ -2972,6 +3095,23 @@ def new_album iter[0] = iter[1] = v.to_s } nperpagecombo.active = 0 + + multilanguages_value = nil + vb.add(ml = Gtk::HBox.new(false, 3).pack_start(ml_label = Gtk::Label.new(utf8(_("Multi-languages: disabled."))), false, false, 0). + pack_start(multilanguages = Gtk::Button.new(utf8(_("Configure multi-languages"))), false, false, 0)) + tooltips.set_tip(ml, utf8(_("When disabled, the web-album will be generated with navigation in your desktop language. When enabled, the web-album will be generated with navigation in all languages you select, but you have to publish your web-album on an Apache web-server for that feature to work.")), nil) + multilanguages.signal_connect('clicked') { + retval = ask_multi_languages(multilanguages_value) + if retval[0] + multilanguages_value = retval[1] + end + if multilanguages_value + ml_label.text = utf8(_("Multi-languages: enabled.")) + else + ml_label.text = utf8(_("Multi-languages: disabled.")) + end + } + vb.add(Gtk::HBox.new(false, 3).pack_start(Gtk::Label.new(utf8(_("'Return to your website' link on pages bottom: "))), false, false, 0). pack_start(indexlinkentry = Gtk::Entry.new, true, true, 0)) tooltips.set_tip(indexlinkentry, utf8(_("Optional HTML markup to use on pages bottom for a small link returning to wherever you see fit in your website (or somewhere else)")), nil) @@ -3194,6 +3334,7 @@ def new_album call_backend("booh-backend --source '#{srcdir}' --destination '#{destdir}' --config-skel '#{configskel}' --for-gui " + "--verbose-level #{$verbose_level} --theme #{theme} --sizes #{sizes} --thumbnails-per-row #{nperrow} " + (nperpage ? "--thumbnails-per-page #{nperpage} " : '') + + (multilanguages_value ? "--multi-languages #{multilanguages_value}" : '') + "#{opt432 ? '--optimize-for-32' : ''} --made-with '#{madewith}' --index-link '#{indexlink}' #{additional_booh_options}", utf8(_("Please wait while scanning source directory...")), 'full scan', @@ -3220,6 +3361,7 @@ def properties end madewith = ($xmldoc.root.attributes['made-with'] || '').gsub(''', '\'') indexlink = ($xmldoc.root.attributes['index-link'] || '').gsub(''', '\'') + save_multilanguages_value = multilanguages_value = $xmldoc.root.attributes['multi-languages'] tooltips = Gtk::Tooltips.new frame1 = Gtk::Frame.new(utf8(_("Locations"))).add(tbl = Gtk::Table.new(0, 0, false)) @@ -3264,6 +3406,25 @@ def properties nperpagecombo.active = 0 end + vb.add(ml = Gtk::HBox.new(false, 3).pack_start(ml_label = Gtk::Label.new, false, false, 0). + pack_start(multilanguages = Gtk::Button.new(utf8(_("Configure multi-languages"))), false, false, 0)) + tooltips.set_tip(ml, utf8(_("When disabled, the web-album will be generated with navigation in your desktop language. When enabled, the web-album will be generated with navigation in all languages you select, but you have to publish your web-album on an Apache web-server for that feature to work.")), nil) + ml_update = proc { + if save_multilanguages_value + ml_label.text = utf8(_("Multi-languages: enabled.")) + else + ml_label.text = utf8(_("Multi-languages: disabled.")) + end + } + ml_update.call + multilanguages.signal_connect('clicked') { + retval = ask_multi_languages(save_multilanguages_value) + if retval[0] + save_multilanguages_value = retval[1] + end + ml_update.call + } + vb.add(Gtk::HBox.new(false, 3).pack_start(Gtk::Label.new(utf8(_("'Return to your website' link on pages bottom: "))), false, false, 0). pack_start(indexlinkentry = Gtk::Entry.new, true, true, 0)) if indexlink @@ -3364,7 +3525,7 @@ def properties save_indexlink = indexlinkentry.text.gsub('"', '"').gsub('\'', ''') dialog.destroy - if ok && (save_theme != theme || save_limit_sizes != limit_sizes || save_opt432 != opt432 || save_nperrow != nperrow || save_nperpage != nperpage || save_madewith != madewith || save_indexlink != indexlinkentry) + if ok && (save_theme != theme || save_limit_sizes != limit_sizes || save_opt432 != opt432 || save_nperrow != nperrow || save_nperpage != nperpage || save_madewith != madewith || save_indexlink != indexlinkentry || save_multilanguages_value != multilanguages_value) if save_theme != theme #- some sort of automatic theme preference $config['default-theme'] = save_theme @@ -3374,6 +3535,7 @@ def properties call_backend("booh-backend --use-config '#{$filename}' --for-gui --verbose-level #{$verbose_level} " + "--thumbnails-per-row #{save_nperrow} --theme #{save_theme} --sizes #{save_limit_sizes.join(',')} " + (save_nperpage ? "--thumbnails-per-page #{save_nperpage} " : '') + + (save_multilanguages_value ? "--multi-languages #{save_multilanguages_value}" : '') + "#{save_opt432 ? '--optimize-for-32' : ''} --made-with '#{save_madewith}' --index-link '#{save_indexlink}' #{additional_booh_options}", utf8(_("Please wait while scanning source directory...")), 'full scan', @@ -3773,9 +3935,14 @@ def create_menu_and_toolbar call_backend("booh-backend --config '#{$filename}' --verbose-level #{$verbose_level} #{additional_booh_options}", utf8(_("Please wait while generating web-album...\nThis may take a while, please be patient.")), 'web-album', - { :successmsg => utf8(_("Your web-album is now ready in directory '%s'. + { :successmsg => $xmldoc.root.attributes['multi-languages'] ? + utf8(_("Your web-album is now ready in directory '%s'. +As multi-languages is activated, you will not be able to view it +comfortably in your browser though.") % $xmldoc.root.attributes['destination']) : + utf8(_("Your web-album is now ready in directory '%s'. Click to view it in your browser:") % $xmldoc.root.attributes['destination']), - :successmsg_linkurl => $xmldoc.root.attributes['destination'], + :successmsg_linkurl => $xmldoc.root.attributes['multi-languages'] ? $xmldoc.root.attributes['destination'] : + $xmldoc.root.attributes['destination'] + '/index.html', :closure_after => proc { $xmldoc.elements.each('//dir') { |elem| $modified ||= elem.attributes['already-generated'].nil? diff --git a/bin/booh-backend b/bin/booh-backend index abe3caa..6a1d350 100755 --- a/bin/booh-backend +++ b/bin/booh-backend @@ -31,8 +31,6 @@ require 'booh/html-merges' #- bind text domain as soon as possible because some _() functions are called early to build data structures bindtextdomain("booh") -SUPPORTED_LANGUAGES = %w(en de fr ja eo) - #- options $options = [ [ '--help', '-h', GetoptLong::NO_ARGUMENT, _("Get help message") ], @@ -692,7 +690,7 @@ def save_html(html, base_filename) html = html.join("\n") end if $multi_languages - for language in $multi_languages[0] + for language in ($multi_languages[0] + $multi_languages[1]).uniq bindtextdomain("booh", { :locale => "#{language}.UTF-8" }) ios = File.open("#{base_filename}.#{language}.html", "w") ios.write(html.gsub(/@@(.*?)@@/) { _($1) }) diff --git a/lib/booh/booh-lib.rb b/lib/booh/booh-lib.rb index 7ee4a9f..bef8574 100644 --- a/lib/booh/booh-lib.rb +++ b/lib/booh/booh-lib.rb @@ -70,6 +70,13 @@ module Booh return sizename end end + + SUPPORTED_LANGUAGES = %w(en de fr ja eo) + + def langname(lang) + langnames = { 'en' => _("english"), 'de' => _("german"), 'fr' => _("french"), 'ja' => _("japanese"), 'eo' => _("esperanto") } + return langnames[lang] + end def from_utf8(string) return Iconv::iconv($CURRENT_CHARSET, "UTF-8", string).to_s -- 2.30.2