[Jifty-commit] r4324 - in jifty/trunk: lib/Jifty/Plugin
lib/Jifty/Plugin/I18N lib/Jifty/Plugin/I18N/Action
lib/Jifty/Plugin/SkeletonApp share/plugins/Jifty/Plugin/I18N
share/plugins/Jifty/Plugin/I18N/web
share/plugins/Jifty/Plugin/I18N/web/static
share/plugins/Jifty/Plugin/I18N/web/static/js
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Mon Oct 29 00:13:57 EDT 2007
Author: clkao
Date: Mon Oct 29 00:13:52 2007
New Revision: 4324
Added:
jifty/trunk/lib/Jifty/Plugin/I18N/
jifty/trunk/lib/Jifty/Plugin/I18N.pm
jifty/trunk/lib/Jifty/Plugin/I18N/Action/
jifty/trunk/lib/Jifty/Plugin/I18N/Action/SetLang.pm
jifty/trunk/share/plugins/Jifty/Plugin/I18N/
jifty/trunk/share/plugins/Jifty/Plugin/I18N/web/
jifty/trunk/share/plugins/Jifty/Plugin/I18N/web/static/
jifty/trunk/share/plugins/Jifty/Plugin/I18N/web/static/js/
jifty/trunk/share/plugins/Jifty/Plugin/I18N/web/static/js/loc.js
- copied, changed from r4300, /jifty/trunk/share/web/static/js/loc.js
Removed:
jifty/trunk/share/web/static/js/loc.js
Modified:
jifty/trunk/lib/Jifty/Plugin/SkeletonApp/View.pm
Log:
Jifty::Plugin::I18N:
- provides SetLang action
- provides loc.js and other facilities to l10n your javascript along with po.
Added: jifty/trunk/lib/Jifty/Plugin/I18N.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/Plugin/I18N.pm Mon Oct 29 00:13:52 2007
@@ -0,0 +1,72 @@
+use strict;
+use warnings;
+
+package Jifty::Plugin::I18N;
+use base 'Jifty::Plugin';
+
+=head1 NAME
+
+Jifty::Plugin::I18N
+
+=head1 SYNOPSIS
+
+# In your jifty config.yml under the framework section:
+
+ L10N:
+ PoDir: share/po
+ AllowedLang:
+ - en
+ - zh_tw
+ Plugins:
+ - I18N:
+ js: 1
+
+
+=head1 DESCRIPTION
+
+This plugin provides additional i18n facility to jifty's core i18n
+features, such as compiling l10n lexicon for client side javascript,
+and a language selector action.
+
+You will still need to manually do the following to make client side l10n work:
+
+=over
+
+=item Extract strings from your js files into your po file
+
+ jifty po --dir share/web/static/js
+
+=item Generate js dictionary
+
+ jifty po --js
+
+=back
+
+=head2 init
+
+=cut
+
+__PACKAGE__->mk_accessors(qw(js));
+
+sub init {
+ my $self = shift;
+ return if $self->_pre_init;
+
+ my %opt = @_;
+ $self->js( $opt{js} );
+
+ Jifty::Web->add_trigger(
+ name => 'after_include_javascript',
+ callback => sub { $self->_i18n_js(@_) },
+ ) if $self->js;
+}
+
+sub _i18n_js {
+ my $self = shift;
+
+ # js l10n init
+ my $current_lang = Jifty::I18N->get_current_language || 'en';
+ Jifty->web->out(qq{<script type="text/javascript">Localization.init({dict_path: '/static/js/dict', lang: '$current_lang'});</script>});
+}
+
+1;
Added: jifty/trunk/lib/Jifty/Plugin/I18N/Action/SetLang.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/Plugin/I18N/Action/SetLang.pm Mon Oct 29 00:13:52 2007
@@ -0,0 +1,26 @@
+package Jifty::Plugin::I18N::Action::SetLang;
+use strict;
+use DateTime::Locale ();
+
+use Jifty::Param::Schema;
+use Jifty::Action schema {
+
+param lang =>
+ label is _('Language'),
+ render as 'select',
+ # XXX: complete_native_name is way too long
+ valid are defer {[ map { { display => DateTime::Locale->load($_)->native_name, value => $_ } } Jifty::I18N->available_languages ]},
+ default is defer { Jifty::I18N->get_current_language };
+};
+
+sub take_action {
+ my $self = shift;
+ my $lang = $self->argument_value('lang');
+ Jifty->web->session->set(jifty_lang => $lang);
+
+ Jifty::I18N->get_language_handle;
+
+ $self->result->message(_("Hi, we speak %1.", DateTime::Locale->load($lang)->native_name));
+}
+
+1;
Modified: jifty/trunk/lib/Jifty/Plugin/SkeletonApp/View.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/SkeletonApp/View.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/SkeletonApp/View.pm Mon Oct 29 00:13:52 2007
@@ -60,12 +60,6 @@
title { _($title) };
Jifty->web->include_css;
Jifty->web->include_javascript;
-
- if (Jifty->config->framework('L10N')->{js}) {
- # js l10n
- my $current_lang = Jifty::I18N->get_current_language || 'en';
- outs_raw(qq{<script type="text/javascript">Localization.init({dict_path: '/static/js/dict', lang: '$current_lang'});</script>});
- }
};
};
Copied: jifty/trunk/share/plugins/Jifty/Plugin/I18N/web/static/js/loc.js (from r4300, /jifty/trunk/share/web/static/js/loc.js)
==============================================================================
--- /jifty/trunk/share/web/static/js/loc.js (original)
+++ jifty/trunk/share/plugins/Jifty/Plugin/I18N/web/static/js/loc.js Mon Oct 29 00:13:52 2007
@@ -5,9 +5,6 @@
this.dict_path = params["dict_path"]
this.dict = this.load_dict(this.lang)
}
- Ext.onReady(function() {
- Localization.show_dates_as_local_time();
- })
},
switch_dict: function(lang) {
this.dict = this.load_dict(lang);
@@ -34,18 +31,6 @@
return str;
},
- show_dates_as_local_time: function() {
- var spans = document.getElementsByTagName('span');
- for (var i=0; i<spans.length; i++) {
- if (spans[i].className.match(/\bdatetime\b/i)) {
- var d = this.get_local_time_for_date(spans[i].title);
- if (d != 'NaN') {
- spans[i].innerHTML = d;
- }
- }
- }
- },
-
get_local_time_for_date: function(time) {
system_date = new Date(time);
user_date = new Date();
More information about the Jifty-commit
mailing list