Permalink
Browse files

Added the option to only show tokens of specific context, added sever…

…al notes and references to the translation documentation for understandment
  • Loading branch information...
Getty committed Jan 6, 2013
1 parent db35e0b commit 32da389d54ae213a2f6faac3652199fdd9d9d9fb
@@ -71,6 +71,36 @@ belongs_to 'token_domain', 'DDGC::DB::Result::Token::Domain', 'token_domain_id';
has_many 'token_screens', 'DDGC::DB::Result::Token::Screen', 'token_id';
has_many 'token_languages', 'DDGC::DB::Result::Token::Language', 'token_id';
+sub has_placeholders {
+ my ( $self ) = @_;
+ my @all_placeholders;
+ my %placeholders = %{$self->placeholders};
+ push @all_placeholders, @{$placeholders{msgid}};
+ push @all_placeholders, @{$placeholders{msgid_plural}} if defined $placeholders{msgid_plural};
+ return scalar @all_placeholders;
+}
+
+my $placeholders_regexp = qr/%(\d+\$)?([-+\'#0 ]*)(\*\d+\$|\*|\d+)?(\.(\*\d+\$|\*|\d+))?([scboxXuidfegEG])/;
+
+sub _parse_placeholders {
+ my ( $self, $string ) = @_;
+ my @matches = $string =~ /$placeholders_regexp/g;
+ my @placeholders;
+ for (@matches) {
+ push @placeholders, $_ if $_;
+ }
+ return @placeholders;
+}
+
+sub placeholders {
+ my ( $self ) = @_;
+ my %placeholders = (
+ msgid => [$self->_parse_placeholders($self->msgid)],
+ );
+ $placeholders{msgid_plural} = [$self->_parse_placeholders($self->msgid_plural)] if $self->msgid_plural;
+ return \%placeholders;
+}
+
sub insert {
my $self = shift;
my $guard = $self->result_source->schema->txn_scope_guard;
@@ -144,55 +144,59 @@ sub comments {
});
}
-sub search_tokens {
- my ( $self, $page, $pagesize, $search ) = @_;
+sub _get_token_languages {
+ my ( $self, $type, $page, $pagesize, $vars, $extra ) = @_;
+ $vars = {} unless defined $vars;
+ $extra = {} unless defined $extra;
$self->token_languages->search({
- 'token.type' => 1,
- 'token.msgid' => { -like => '%'.$search.'%'},
- 'token.msgid_plural' => { -like => '%'.$search.'%'},
- 'token.msgctxt' => { -like => '%'.$search.'%'},
- 'token.notes' => { -like => '%'.$search.'%'},
+ 'token.type' => $type,
+ %{$vars},
},{
order_by => 'me.created',
( ( defined $page and defined $pagesize ) ? (
page => $page,
rows => $pagesize,
) : () ),
prefetch => 'token',
+ %{$extra},
+ });
+}
+
+sub search_tokens {
+ my ( $self, $page, $pagesize, $search ) = @_;
+ $self->_get_token_languages(1, $page, $pagesize, {
+ 'token.msgid' => { -like => '%'.$search.'%'},
+ 'token.msgid_plural' => { -like => '%'.$search.'%'},
+ 'token.msgctxt' => { -like => '%'.$search.'%'},
+ 'token.notes' => { -like => '%'.$search.'%'},
+ },{
join => 'token_language_translations',
});
}
sub untranslated_tokens {
my ( $self, $page, $pagesize ) = @_;
- $self->token_languages->search({
- 'token.type' => 1,
+ $self->_get_token_languages(1, $page, $pagesize, {
'token_language_translations.id' => undef,
},{
- order_by => 'me.created',
- ( ( defined $page and defined $pagesize ) ? (
- page => $page,
- rows => $pagesize,
- ) : () ),
- prefetch => 'token',
join => 'token_language_translations',
});
}
-sub all_tokens {
- my ( $self, $page, $pagesize ) = @_;
- $self->token_languages->search({
- 'token.type' => 1,
+sub msgctxt_tokens {
+ my ( $self, $page, $pagesize, $msgctxt ) = @_;
+ $self->_get_token_languages(1, $page, $pagesize, {
+ 'token.msgctxt' => $msgctxt,
},{
- order_by => 'me.created',
- ( ( defined $page and defined $pagesize ) ? (
- page => $page,
- rows => $pagesize,
- ) : () ),
- prefetch => 'token',
+ join => 'token_language_translations',
});
}
+sub all_tokens {
+ my ( $self, $page, $pagesize ) = @_;
+ $self->_get_token_languages(1, $page, $pagesize);
+}
+
use overload '""' => sub {
my $self = shift;
return 'Token-Domain-Language for '.$self->token_domain->key.' with locale '.$self->language->locale;
@@ -219,7 +219,13 @@ sub snippets :Chained('locale') :Args(0) {
$c->user->update;
}
$c->stash->{placeholder_notes} = $placeholder_notes;
- $c->pager_init($c->action.$c->stash->{token_domain}->key.$c->stash->{locale},20);
+ $c->pager_init(
+ $c->action.
+ $c->stash->{token_domain}->key.
+ $c->stash->{locale}.
+ ( $c->req->params->{only_untranslated} ? "1" : "0" ).
+ ( defined $c->req->params->{only_msgctxt} ? '"'.$c->req->params->{only_msgctxt}.'"' : "undef" )
+ ,20);
my $save_translations = $c->req->params->{save_translations} || $c->req->params->{save_translations_next_page} ? 1 : 0;
my $next_page = $c->req->params->{save_translations_next_page} ? 1 : 0;
$self->save_translate_params($c) if ($save_translations);
@@ -229,6 +235,9 @@ sub snippets :Chained('locale') :Args(0) {
} elsif ($c->req->params->{only_untranslated}) {
$c->stash->{only_untranslated} = 1;
$c->stash->{token_languages} = $c->stash->{locales}->{$c->stash->{locale}}->{tcl}->untranslated_tokens($c->stash->{page},$c->stash->{pagesize});
+ } elsif (defined $c->req->params->{only_msgctxt}) {
+ $c->stash->{only_msgctxt} = $c->req->params->{only_msgctxt};
+ $c->stash->{token_languages} = $c->stash->{locales}->{$c->stash->{locale}}->{tcl}->msgctxt_tokens($c->stash->{page},$c->stash->{pagesize},$c->stash->{only_msgctxt});
} else {
$c->stash->{token_languages} = $c->stash->{locales}->{$c->stash->{locale}}->{tcl}->all_tokens($c->stash->{page},$c->stash->{pagesize});
}
@@ -8,11 +8,12 @@
<@ FOR token_language IN token_languages.all @>
<div>
<div>
- <a href="<@ u('Translate','tokenlanguage',token_language.id) @>">
- <@ token_language.token.msgctxt @>
- <@ IF token_language.token.msgctxt @>/<@ END @>
+ <a href="<@ u('Translate','tokenlanguage',token_language.id) @>">
+ <@ IF token_language.token.msgctxt @>
+ [<@ token_language.token.msgctxt @>]
+ <@ END @>
<@ token_language.token.msgid @>
- <@ IF token_language.token.msgid_plural @>/<@ END @>
+ <@ IF token_language.token.msgid_plural @>|<@ END @>
<@ token_language.token.msgid_plural @>
</a>
<@ IF token_language.msgstr @>
@@ -14,20 +14,22 @@
<!-- RIGHT !-->
<div class="token-filter_right">
<div class="token_menu">
- <a href="#" class="token_search_toggle">
- Search
- </a> |
- <a href="<@ u('Translate','allsnippets',token_domain.key,cur_language.locale) @>">
- Snippets overview
- </a> |
- <a href="<@ u('Translate','locale_comments',token_domain.key,cur_language.locale) @>">
- <@ l('Discuss') @>
- </a> |
+ <@ UNLESS only_msgctxt @>
+ <a href="<@ u('Translate','allsnippets',token_domain.key,cur_language.locale) @>">
+ Snippets overview
+ </a> |
+ <a href="<@ u('Translate','locale_comments',token_domain.key,cur_language.locale) @>">
+ <@ l('Discuss') @>
+ </a> |
+ <@ END @>
<@ IF only_untranslated || token_search @>
<a href="<@ u('Translate','snippets',token_domain.key,cur_language.locale) @>"><@ l('Show all snippets') @></a>
<@ IF only_untranslated @>
<input type="hidden" name="only_untranslated" value="1" />
<@ END @>
+ <@ ELSIF only_msgctxt @>
+ Only tokens of context <b>"<@ only_msgctxt @>"</b>
+ <input type="hidden" name="only_msgctxt" value="<@ only_msgctxt @>" />
<@ ELSE @>
<a href="<@ u('Translate','snippets',token_domain.key,cur_language.locale,{ only_untranslated => 1 }) @>"><@ l('Show only untranslated snippets') @></a>
<@ END @>
@@ -21,7 +21,12 @@
<@ IF token_language.token.msgctxt @>
<tr>
<td><h2><@ l('Context') @></h2></td>
- <td><@ token_language.token.msgctxt @> (Ignore this, do not translate)</td>
+ <td>
+ <a target="translate_snippets_<@ token_domain.key @>_<@ cur_language.locale @>_<@ token_language.token.msgctxt @>" href="<@ u('Translate','snippets',token_domain.key,cur_language.locale,{ only_msgctxt => token_language.token.msgctxt }) @>">
+ <@ token_language.token.msgctxt @>
+ </a>
+ <div class="note">This is the <a href="https://github.com/duckduckgo/duckduckgo/blob/master/lib/DDG/Manual/Translation.pod#token-with-context">context</a>, do not translate it, click it for getting an extra browser window with all tokens of this context</div>
+ </td>
<td>&nbsp;</td>
</tr>
<tr>
@@ -68,7 +73,28 @@
<@ END @>
<@ IF c.user.can_speak(token_language.token_domain_language.language.locale) @>
-
+ <@ IF token_language.token.msgctxt || token_language.token.has_placeholders @>
+ <div class="note"><strong>Note!</strong> This token has
+ <@- IF token_language.token.msgctxt -@>
+ <a href="https://github.com/duckduckgo/duckduckgo/blob/master/lib/DDG/Manual/Translation.pod#token-with-context">context</a>
+ <@- END -@>
+ <@- IF token_language.token.msgctxt && token_language.token.has_placeholders -@>
+ &nbsp;and&nbsp;
+ <@- END -@>
+ <@- IF token_language.token.has_placeholders -@>
+ <a href="https://github.com/duckduckgo/duckduckgo/blob/master/lib/DDG/Manual/Translation.pod#placeholders-in-tokens">placeholders</a>
+ <@- END -@>.
+ Only translate it, if you are 100% sure in which way it is used!
+ <@ IF token_language.token.has_placeholders @>
+ A wrong translation can destroy <a href="https://github.com/duckduckgo/duckduckgo/blob/master/lib/DDG/Manual/Translation.pod#combined-tokens">combined tokens</a> very easily! Also be sure the same amount of placeholders is in your translation as in the token!
+ <@ END @>
+ <@ IF token_language.token.notes || token_language.notes @>
+ Please assure to read the notes before translating!
+ <@ ELSE @>
+ Please do not hesitate to <a href="https://duckduckgo.com/feedback">contact us</a>, if you require any further information for this token.
+ <@ END @>
+ </div><br/>
+ <@ END @>
<div id="token_own_<@ token_language.id @>_toggle">
<@ FOR n IN [ 0..token_language.max_msgstr_index ] @>
<@ SET func = 'msgstr' _ n @>

0 comments on commit 32da389

Please sign in to comment.