1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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();
|