[Catalyst-commits] r6222 - in trunk/Catalyst-Plugin-I18N-DBIC: . t

bricas at dev.catalyst.perl.org bricas at dev.catalyst.perl.org
Wed Mar 28 12:59:13 GMT 2007


Author: bricas
Date: 2007-03-28 12:59:12 +0100 (Wed, 28 Mar 2007)
New Revision: 6222

Added:
   trunk/Catalyst-Plugin-I18N-DBIC/Changes
   trunk/Catalyst-Plugin-I18N-DBIC/DBIC.pm
   trunk/Catalyst-Plugin-I18N-DBIC/MANIFEST
   trunk/Catalyst-Plugin-I18N-DBIC/META.yml
   trunk/Catalyst-Plugin-I18N-DBIC/Makefile.PL
   trunk/Catalyst-Plugin-I18N-DBIC/t/
   trunk/Catalyst-Plugin-I18N-DBIC/t/01use.t
   trunk/Catalyst-Plugin-I18N-DBIC/t/02pod.t
   trunk/Catalyst-Plugin-I18N-DBIC/t/03podcoverage.t
Log:
Import Catalyst::Plugin::I18N::DBIC

Added: trunk/Catalyst-Plugin-I18N-DBIC/Changes
===================================================================
--- trunk/Catalyst-Plugin-I18N-DBIC/Changes	                        (rev 0)
+++ trunk/Catalyst-Plugin-I18N-DBIC/Changes	2007-03-28 11:59:12 UTC (rev 6222)
@@ -0,0 +1,4 @@
+Revision history for Catalyst::Plugin::I18N::DBIC
+
+0.04 2007-03-25 12:39:00
+    - added support for alternative names for the lexicon table

Added: trunk/Catalyst-Plugin-I18N-DBIC/DBIC.pm
===================================================================
--- trunk/Catalyst-Plugin-I18N-DBIC/DBIC.pm	                        (rev 0)
+++ trunk/Catalyst-Plugin-I18N-DBIC/DBIC.pm	2007-03-28 11:59:12 UTC (rev 6222)
@@ -0,0 +1,167 @@
+package Catalyst::Plugin::I18N::DBIC;
+
+use strict;
+use warnings;
+
+use base 'Catalyst::Plugin::I18N';
+
+our $VERSION = '0.04';
+
+sub load_lexicon {
+    my ($c, @paths) = @_;
+
+    my $class = ref $c || $c;
+    my $lang = $c->language;
+
+    my $where = {
+        language    => $lang,
+        path        => [@paths],
+    };
+
+    my $lexicon_model = $c->config->{'I18N::DBIC'}{lexicon} || 'DBIC::Lexicon';
+    my $lexicons_rs = $c->model($lexicon_model)->search($where);
+
+    while (my $lex = $lexicons_rs->next) {
+        my $message = $lex->message;
+        my $value = $lex->value;
+
+        eval <<"EOF";
+            \$$class\::I18N::$lang\::Lexicon{\$message} = \$value;
+EOF
+        if ($@) {
+            $c->log->error(qq/Couldn't write $class::I18N::$lang, "$@"/);
+        }
+    }
+}
+
+1;
+
+=pod
+
+=head1 NAME
+
+Catalyst::Plugin::I18N::DBIC - Internationalization for Catalyst, data loaded
+from database
+
+=head1 SYNOPSIS
+
+  use Catalyst qw(-Debug I18N::DBIC);
+
+  __PACKAGE__->config(
+      name => 'MyApp',
+      'I18N::DBIC'    => {
+          lexicon_model   => 'DBIC::MyLexicon',
+      },
+  );
+
+You can load the lexicon in your controller.
+
+  $c->languages( ['de'] );
+  $c->load_lexicon( qw(footer header user/list navigation) );
+  print $c->localize('Hello Catalyst');
+
+Or in your template
+
+  [% c.load_lexicon('header', 'navigation') %]
+
+  [% c.loc('Home Page') %]
+  [% c.loc('Welcome to Catalyst') %]
+
+=head1 DESCRIPTION
+
+This module is based on L<Catalyst::Plugin::I18N> and L<I18N> and you should
+refer to those modules for further information.
+
+These modules hold their localization data in files (mo, po or pm files) and
+for a very large application these files can become very large and difficult
+to maintain.
+
+L<Catalyst::Plugin::I18N::DBIC> however allows you to hold the localization
+data in a database (using L<Catalyst::Model::DBIC::Schema> ) which has
+several advantages.
+
+=over 4
+
+=item
+
+The localization data can be split into several 'paths' which represent the
+natural organization of the application. e.g. 'footer', 'header', 'navigation',
+'user/list'.
+
+=item
+
+You can write an application that directly modifies the database so that
+your translators can do their stuff more easily and directly.
+
+=item
+
+If you have a client that requires custom text it is easier to do this by
+making a database change than by releasing a new text file.
+
+=back
+
+=head1 EXTENDED METHODS
+
+=head2 load_lexicon
+
+Takes an array of 'paths' which should be searched to load the Lexicon data
+from the database.
+
+It is more efficient in database requests to request all paths that may be
+used on a page in one go. It may however be more convenient to make several
+requests if you include templates in other templates (such as header and
+footer templates) and make separate calls in each template.
+
+=head1 Database Schema
+
+The module requires a table called C<lexicon> with the following structure
+
+  CREATE TABLE lexicon (
+    id          int(11) NOT NULL auto_increment,
+    language    varchar(15)     default NULL,
+    path        varchar(255)    default NULL,
+    message     text,
+    value       text,
+    notes       text,
+    PRIMARY KEY (id)
+  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+By default the table C<lexicon> is used if you don't specify the
+lexicon_model in the config. If you use an alternative table you must still
+use the same structure.
+
+Actually you may want to change the index method and the 'notes' field is not
+required but can be useful to hold information to help the translator put the
+message in context.
+
+The C<value> is the tranlated C<message>. The C<path> is the context where
+the message is used. For example you may wish to group all the menu button
+text and navigation text into the C<navigation> path. All the text for the
+generic header template could be in the C<header> path etc.
+
+=head1 SEE ALSO
+
+Refer to L<Catalyst::Plugin::I18N> for information on the other methods used.
+
+=head1 TO-DO
+
+=over 4
+
+=item Implement caching methods on-demand or pre-load
+=item Reduce name clashes for text by making use of the path data
+
+=back
+
+=head1 AUTHOR
+
+Ian Docherty, C<cpan at iandocherty.com>
+
+With thanks to Kazuma Shiraiwa, Brian Cassidy and others for feedback and advice.
+
+=head1 COPYRIGHT & LICENSE
+
+	Copyright (c) 2005 the aforementioned authors. All rights
+	reserved. This program is free software; you can redistribute
+	it and/or modify it under the same terms as Perl itself.
+
+=cut

Added: trunk/Catalyst-Plugin-I18N-DBIC/MANIFEST
===================================================================
--- trunk/Catalyst-Plugin-I18N-DBIC/MANIFEST	                        (rev 0)
+++ trunk/Catalyst-Plugin-I18N-DBIC/MANIFEST	2007-03-28 11:59:12 UTC (rev 6222)
@@ -0,0 +1,7 @@
+DBIC.pm
+MANIFEST
+Makefile.PL
+t/01use.t
+t/02pod.t
+t/03podcoverage.t
+META.yml

Added: trunk/Catalyst-Plugin-I18N-DBIC/META.yml
===================================================================
--- trunk/Catalyst-Plugin-I18N-DBIC/META.yml	                        (rev 0)
+++ trunk/Catalyst-Plugin-I18N-DBIC/META.yml	2007-03-28 11:59:12 UTC (rev 6222)
@@ -0,0 +1,13 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
+name:         Catalyst-Plugin-I18N-DBIC
+version:      0.01
+version_from: DBIC.pm
+installdirs:  site
+requires:
+    Catalyst:                       2.99
+    Catalyst-Plugin-I18N-DBIC:      0
+    Catalyst-Plugin-DBIC:           0
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.30

Added: trunk/Catalyst-Plugin-I18N-DBIC/Makefile.PL
===================================================================
--- trunk/Catalyst-Plugin-I18N-DBIC/Makefile.PL	                        (rev 0)
+++ trunk/Catalyst-Plugin-I18N-DBIC/Makefile.PL	2007-03-28 11:59:12 UTC (rev 6222)
@@ -0,0 +1,13 @@
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    NAME            => 'Catalyst::Plugin::I18N::DBIC',
+    AUTHOR          => 'Ian Docherty (cpan at iandocherty.com)',
+    PREREQ_PM => {
+        'Catalyst'                  => '2.99',
+        'Catalyst::Plugin::I18N'    => '0',
+        'Catalyst::Model::DBIC'     => '0',
+    },
+    VERSION_FROM    => 'DBIC.pm',
+    ABSTRACT        => 'Obtain locale text from database',
+);

Added: trunk/Catalyst-Plugin-I18N-DBIC/t/01use.t
===================================================================
--- trunk/Catalyst-Plugin-I18N-DBIC/t/01use.t	                        (rev 0)
+++ trunk/Catalyst-Plugin-I18N-DBIC/t/01use.t	2007-03-28 11:59:12 UTC (rev 6222)
@@ -0,0 +1,4 @@
+use strict;
+use Test::More tests => 1;
+
+BEGIN { use_ok('Catalyst::Plugin::I18N::DBIC') }

Added: trunk/Catalyst-Plugin-I18N-DBIC/t/02pod.t
===================================================================
--- trunk/Catalyst-Plugin-I18N-DBIC/t/02pod.t	                        (rev 0)
+++ trunk/Catalyst-Plugin-I18N-DBIC/t/02pod.t	2007-03-28 11:59:12 UTC (rev 6222)
@@ -0,0 +1,7 @@
+use Test::More;
+
+eval "use Test::Pod 1.14";
+plan skip_all => 'Test::Pod 1.14 required' if $@;
+plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
+
+all_pod_files_ok();

Added: trunk/Catalyst-Plugin-I18N-DBIC/t/03podcoverage.t
===================================================================
--- trunk/Catalyst-Plugin-I18N-DBIC/t/03podcoverage.t	                        (rev 0)
+++ trunk/Catalyst-Plugin-I18N-DBIC/t/03podcoverage.t	2007-03-28 11:59:12 UTC (rev 6222)
@@ -0,0 +1,7 @@
+use Test::More;
+
+eval "use Test::Pod::Coverage 1.04";
+plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@;
+plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
+
+all_pod_coverage_ok();




More information about the Catalyst-commits mailing list