aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2013-07-31 12:47:36 +0100
committerStruan Donald <struan@exo.org.uk>2013-07-31 12:47:36 +0100
commit8d78eb386329bc71eb8a520d4142f8c9c9956f89 (patch)
treed367a0f13fd7e60b4be6bd24ad35d0be98346a6c
parentbaea7267627a5a0e9293785a01e503114a3deee5 (diff)
Remove hardcoding of translation language
Now we have a list of translation languages to generate files for.
-rw-r--r--bin/localise_templates36
1 files changed, 26 insertions, 10 deletions
diff --git a/bin/localise_templates b/bin/localise_templates
index 372535b..3267433 100644
--- a/bin/localise_templates
+++ b/bin/localise_templates
@@ -5,9 +5,16 @@ use warnings;
use Template;
use mySociety::Locale;
-mySociety::Locale::negotiate_language('de-ch,German,de_CH');
-mySociety::Locale::gettext_domain('ZurichMobileApp');
-mySociety::Locale::change('de-ch');
+sub get_langs {
+ my $lang_list = 'locale/lang_list';
+ my @langs = do {
+ open my $f, '<', $lang_list
+ or die "Can't open $lang_list: $!\n";
+ <$f>;
+ };
+
+ return @langs;
+}
sub loc {
my @args = @_;
@@ -20,17 +27,26 @@ sub tprintf {
return sprintf $format, @args;
}
-my $t = Template->new({
- INCLUDE_PATH => 'templates',
- OUTPUT_PATH => 'compiled'
-});
my $vars = {
loc => \&loc,
tprintf => \&tprintf,
};
-for my $file ( glob('templates/*') ) {
- $file =~ s%templates/%%;
- $t->process( $file, $vars, $file ) or warn $t->error;
+for my $lang ( get_langs() ) {
+ my @lang_parts = split(',', $lang);
+
+ mySociety::Locale::negotiate_language($lang);
+ mySociety::Locale::gettext_domain('FixMyStreetMobileApp');
+ mySociety::Locale::change($lang_parts[0]);
+
+ my $t = Template->new({
+ INCLUDE_PATH => 'templates',
+ OUTPUT_PATH => 'compiled/' . $lang_parts[0]
+ });
+
+ for my $file ( glob('templates/*') ) {
+ $file =~ s%templates/%%;
+ $t->process( $file, $vars, $file ) or warn $t->error;
+ }
}