Skip to content
Browse files

Startup of the public repository of duckduckgo open source parts

  • Loading branch information...
0 parents commit 7af6025d60001b3a260e968bf6153bb19dd9bef0 @Getty Getty committed Oct 15, 2011
Showing with 156 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +3 −0 Changes
  3. +52 −0 dist.ini
  4. +37 −0 ex/translate.pl
  5. +7 −0 lib/DDG.pm
  6. +43 −0 lib/DDG/Util/Translate.pm
  7. +12 −0 t/00-load.t
2 .gitignore
@@ -0,0 +1,2 @@
+DDG-*
+.build
3 Changes
@@ -0,0 +1,3 @@
+Revision history for {{$dist->name}}
+
+{{$NEXT}}
52 dist.ini
@@ -0,0 +1,52 @@
+name = DDG
+author = Torsten Raudssus <torsten@raudssus.de>
+license = Perl_5
+copyright_holder = DuckDuckGo, Inc. L<http://duckduckgo.com/>
+copyright_year = 2011
+
+[Prereqs]
+File::ShareDir::ProjectDistDir = 0
+MooseX::Getopt = 0.37
+Digest::MD5 = 2.51
+IO::All = 0.41
+JSON = 2.53
+Moose = 2.0205
+namespace::autoclean = 0.13
+Template = 2.22
+Template::Plugin::Capture = 0.01
+Template::Provider::Encoding = 0.10
+YAML = 0.73
+YAML::XS = 0.35
+File::Path = 2.08
+MooseX::NonMoose = 0.22
+Data::Printer = 0
+File::Spec = 3.33
+Data::Localize = 0.00020
+
+[Prereqs / TestRequires]
+Test::More = 0.98
+Test::Dirs = 0.03
+File::Temp = 0.22
+
+[GatherDir]
+[PruneCruft]
+[ManifestSkip]
+[ExtraTests]
+[ExecDir]
+[ShareDir]
+[MakeMaker]
+[Manifest]
+; [TestRelease]
+; [ConfirmRelease]
+[MetaJSON]
+[MetaYAML]
+
+[Git::NextVersion]
+version_regexp = ^(.+)$
+[PkgVersion]
+[PodSyntaxTests]
+[GithubMeta]
+[Repository]
+
+[@Git]
+tag_format = %v
37 ex/translate.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use FindBin;
+use lib $FindBin::Dir . "/../lib";
+
+use 5.010;
+
+use DDG::Util::Translate;
+
+#
+# you need the generated po files, made by script/ddgc_pogenerator.pl from the community-platform repo
+#
+
+l_add_context('duckduckgo-results','po-files/duckduckgo-results');
+l_add_context('test-context','po-files/test-context');
+
+l_set_locales('de_DE');
+
+l_set_context('test-context');
+
+say l('Hello %1','stranger');
+say l('You are %1 from %2','german','germany');
+
+l_set_locales('ru_RU');
+
+say l('Hello %1','stranger');
+say l('You are %1 from %2','russian','russia');
+
+l_set_context('duckduckgo-results');
+
+say l('try');
+
+# ------------------------------
+
+say l('Hello %1','stranger');
7 lib/DDG.pm
@@ -0,0 +1,7 @@
+package DDG;
+# ABSTRACT: DuckDuckGo Search Engines Open Source Parts
+
+use strict;
+use warnings;
+
+1;
43 lib/DDG/Util/Translate.pm
@@ -0,0 +1,43 @@
+package DDG::Util::Translate;
+
+use strict;
+use warnings;
+
+use Exporter 'import';
+
+our @EXPORT = qw( l l_set_locales l_add_context l_set_context );
+
+use Data::Localize;
+use IO::All;
+
+my %cons;
+my @locales;
+my $current;
+
+sub l { $current->localize(@_) }
+
+sub l_add_context {
+ my $contextname = shift;
+ my $contextdir = shift;
+ die "[DDG::Util::Translate] need contextname and contextdir" unless $contextname && $contextdir;
+ $cons{$contextname} = Data::Localize->new();
+ $cons{$contextname}->add_localizer(
+ class => 'Gettext',
+ path => $contextdir.'/*.po',
+ );
+ $cons{$contextname}->set_languages(@locales);
+}
+
+sub l_set_locales {
+ @locales = @_;
+ $_->set_languages(@locales) for (values %cons);
+}
+
+sub l_set_context {
+ my $contextname = shift;
+ die "[DDG::Util::Translate] need contextname" unless $contextname;
+ die "[DDG::Util::Translate] requested context ".$contextname." is not loaded" unless defined $cons{$contextname};
+ $current = $cons{$contextname};
+}
+
+1;
12 t/00-load.t
@@ -0,0 +1,12 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+
+BEGIN {
+ use_ok('DDG');
+ use_ok('DDG::Util::Translate');
+}
+
+done_testing;

0 comments on commit 7af6025

Please sign in to comment.
Something went wrong with that request. Please try again.