diff options
Diffstat (limited to 't/i18n.t')
-rw-r--r-- | t/i18n.t | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/t/i18n.t b/t/i18n.t new file mode 100644 index 000000000..6a5d94fa2 --- /dev/null +++ b/t/i18n.t @@ -0,0 +1,39 @@ +use strict; +use warnings; + +use Test::More; + +use FixMyStreet; +use mySociety::Locale; + +# check that the mo files have been generated +die "You need to run 'commonlib/bin/gettext-makemo --quiet FixMyStreet' " + . "to generate the *.mo files needed." + unless -e FixMyStreet->path_to( + 'locale/cy_GB.UTF-8/LC_MESSAGES/FixMyStreet-EmptyHomes.mo'); + +# Example strings +my $english = "Sorry! Something's gone wrong."; +my $welsh = "Ymddiheuriadau! Mae rhywbeth wedi mynd o'i le."; + +# set english as the language +mySociety::Locale::negotiate_language( # + 'en-gb,English,en_GB|cy,Cymraeg,cy_GB', 'en_GB' +); + +mySociety::Locale::gettext_domain( 'FixMyStreet-EmptyHomes', 1 ); +mySociety::Locale::change(); +is _($english), $english, "english to english"; + +# set to welsh and check for translation +mySociety::Locale::change('cy'); +is _($english), $welsh, "english to welsh"; + +# check that being in a deep directory does not confuse the code +chdir FixMyStreet->path_to('t/app/controller') . ''; +mySociety::Locale::gettext_domain( 'FixMyStreet-EmptyHomes', 1, + FixMyStreet->path_to('locale')->stringify ); +mySociety::Locale::change('cy'); +is _($english), $welsh, "english to welsh (deep directory)"; + +done_testing(); |