Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying out Locale::TextDomain. In __("something"), when a translation is not found, whether .mo file can't be found due to unknown locale or the particular string is not translated in the catalog, the original string is returned. While debugging, it would be nice if I can see this. So the question is, is there a way to die or warn on missing translation?

Replies are listed 'Best First'.
Re: Locale::TextDomain: how to die/warn on missing translation?
by Your Mother (Archbishop) on Dec 13, 2013 at 06:31 UTC

    Good question. Probably the answer lies in the xgettext tools/layer. But there is a Perl-based approach that worked for me with similar concerns. A way to do a warning is to do dummy translations of anything in the locale/translation file that isn't already done and fill them up with characters like ▩▩▩▩▩ ▩▩ ▩▩▩▩. It's not a code-based warning or error but becomes obvious in even casual viewing of the site/end-material of what got missed.

    No code I can share right now, sorry, and it's not trivial because of the way the tools work. So, this is actually probably terrible advice even though it did work for me… :|

Re: Locale::TextDomain: how to die/warn on missing translation?
by Anonymous Monk on Dec 13, 2013 at 07:41 UTC
    sub __($) { use Locale::TextDomain; my( $key ) = @_; my( $ret ) = Locale::TextDomain::__($key); if( $key eq $ret ){ warn "blah blah q{$key}\n"; die "blah blah q{$ret}\n"; } return $ret; }
Re: Locale::TextDomain: how to die/warn on missing translation?
by Lennotoecom (Pilgrim) on Dec 13, 2013 at 06:42 UTC
    try something like this
    foreach(split //, $a){ if(!(ord($_)>=97 && ord($_)<=122)){ print "wrong symbol\n"; last; } }
    in this snippet
    you basically compare your string,
    symbol by symbol to ascii codes for a-z

    you may change this in more proper way
    for your particular situation, that's just an example