Localize navigation
Change-Id: Id3e423bbf51916cdff737e9188b6104696a0f5b5
diff --git a/t/docnavi.t b/t/docnavi.t
index a9dc149..122956f 100644
--- a/t/docnavi.t
+++ b/t/docnavi.t
@@ -1,8 +1,8 @@
use Mojo::Base -strict;
-use lib '../lib', 'lib';
use Mojolicious::Lite;
use Test::More;
use Test::Mojo;
+use utf8;
my $t = Test::Mojo->new;
my $app = $t->app;
@@ -16,6 +16,23 @@
# Load plugin to test
$app->plugin('KalamarHelpers');
+my $languages = [qw/en de/];
+$app->plugin('Localize' => {
+ dict => {
+ Nav => {
+ _ => sub { $languages },
+ -en => {
+ faq => 'F.A.Q.',
+ '#default-foundries' => 'Default Foundries',
+ },
+ de => {
+ faq => 'Häufige Fragen',
+ '#default-foundries' => 'Standard Foundries'
+ }
+ }
+ }
+});
+
my $navi = [
{
id => 'korap',
@@ -50,8 +67,8 @@
title => 'KorAP',
items => [
{
- id => 'krill',
- title => 'Krill',
+ id => 'krill',
+ title => 'Krill',
}
]
},
@@ -72,12 +89,12 @@
title => 'KorAP',
items => [
{
- id => 'krill',
- title => 'Krill',
+ id => 'krill',
+ title => 'Krill',
},
{
- id => 'koral',
- title => 'Koral'
+ id => 'koral',
+ title => 'Koral'
}
]
},
@@ -86,22 +103,22 @@
id => 'ql',
items => [
{
- title => 'Cosmas II',
- id => 'cosmas2'
+ title => 'Cosmas II',
+ id => 'cosmas2'
},
{
- 'title' => 'Poliqarp+',
- 'id' => 'poliqarp-plus',
- items => [
- {
- "title" => "Simple Segments",
- "id" => "#segments"
- },
- {
- "title" => "Complex Segments",
- "id" => "#complex"
- }
- ]
+ 'title' => 'Poliqarp+',
+ 'id' => 'poliqarp-plus',
+ items => [
+ {
+ "title" => "Simple Segments",
+ "id" => "#segments"
+ },
+ {
+ "title" => "Complex Segments",
+ "id" => "#complex"
+ }
+ ]
}
]
},
@@ -155,12 +172,12 @@
title => 'KorAP',
items => [
{
- id => 'krill',
- title => 'Krill',
+ id => 'krill',
+ title => 'Krill',
},
{
- id => 'koral',
- title => 'Koral'
+ id => 'koral',
+ title => 'Koral'
}
]
},
@@ -169,23 +186,23 @@
id => 'ql',
items => [
{
- title => 'Cosmas II',
- id => 'cosmas2'
+ title => 'Cosmas II',
+ id => 'cosmas2'
},
{
- 'title' => 'Poliqarp+',
- 'id' => 'poliqarp-plus',
- 'class' => 'folded',
- items => [
- {
- "title" => "Simple Segments",
- "id" => "#segments"
- },
- {
- "title" => "Complex Segments",
- "id" => "#complex"
- }
- ]
+ 'title' => 'Poliqarp+',
+ 'id' => 'poliqarp-plus',
+ 'class' => 'folded',
+ items => [
+ {
+ "title" => "Simple Segments",
+ "id" => "#segments"
+ },
+ {
+ "title" => "Complex Segments",
+ "id" => "#complex"
+ }
+ ]
}
]
},
@@ -205,6 +222,45 @@
'Path matches doc/ql/poliqarp-plus#complex');
like($render, qr!class="folded active".*?Poliqarp\+!, 'Active and folded value for Poliqarp+');
+
+# Test for translations
+$navi = [
+ {
+ id => 'korap',
+ title => 'KorAP',
+ items => [
+ {
+ id => 'krill',
+ title => 'Krill',
+ }
+ ]
+ },
+ {
+ id => 'faq',
+ title => 'F.A.Q.'
+ }
+];
+
+$render = $app->doc_navi($navi);
+like($render, qr!/doc/korap!, 'Path matches doc/korap');
+like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
+like($render, qr!<a href="/doc/korap/krill">Krill</a>!,
+ 'Path matches korap/krill');
+like($render, qr!<a href="/doc/faq">F\.A\.Q\.</a>!,
+ 'Path matches FAQ');
+
+# Change preferred language
+$languages = [qw/de en/];
+
+$render = $app->doc_navi($navi);
+like($render, qr!/doc/korap!, 'Path matches doc/korap');
+like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
+like($render, qr!<a href="/doc/korap/krill">Krill</a>!,
+ 'Path matches korap/krill');
+like($render, qr!<a href="/doc/faq">Häufige Fragen</a>!,
+ 'Path matches FAQ');
+
+
done_testing;
__END__