Difference between revisions of "Translation"

From EPrints Documentation
Jump to: navigation, search
Line 3: Line 3:
 
== Considerations for multilingual sites ==
 
== Considerations for multilingual sites ==
  
In a multilingual site you probably let the visitors to choose the language of the session. It is determined by the default setting of the browser preferences, but sometimes users want to change this. Manual setting of the session's language can be done by the [[http://files.eprints.org/264/ port]] of the ''set_language'' script from earlier Eprintss versions. A handy place for the URL is in the menu at the top of the page. You might want to edit lib/defaultcfg/lang/en/templates/default.xml to put it there:
+
In a multilingual site you probably let the visitors to choose the language of the session. It is determined by the default setting of the browser preferences, but sometimes users want to change this. Manual setting of the session's language can be done by the [[http://files.eprints.org/264/ port]] of the ''set_language'' script from earlier Eprints versions, and should go into the cgi directory. A handy place for the set_language URL is in the menu at the top of the page. You might want to edit lib/defaultcfg/lang/en/templates/default.xml to include this possibility there:
  
 
   <ul class="ep_tm_menu">
 
   <ul class="ep_tm_menu">
Line 12: Line 12:
 
   </ul>
 
   </ul>
  
The template page on other languages should not contain this ''Language'' item as not necessarily will people recognise it. Rather use a button which goes back to ''English":
+
The template page on other languages should not contain this ''Language'' item as not neccessarily will people recognise it. Rather use a button which goes back to the standard ''English":
  
 
   <li><a href="{$config{perl_url}/set_lang?langid=en">In English</a></li>
 
   <li><a href="{$config{perl_url}/set_lang?langid=en">In English</a></li>
  
By default, all e-mail messages are sent out on the default language. You might let the users to choose their preferred language so that they receive messages on their preferred language. The ''lang'' field is defined for all users; the value can be set automatically in  
+
By default, all e-mail messages are sent out on the default language of the depository. You might let users choose their preferred language so that they'll receive messages on that language. The ''lang'' (system) field is defined for all users; the value can be set automatically in  
defaultcfg/cfg.d/user_fields_automatic.pl
+
defaultcfg/cfg.d/user_fields_automatic.pl for example by
  
 
  $c->{set_user_automatic_fields} = sub
 
  $c->{set_user_automatic_fields} = sub
Line 25: Line 25:
 
         $user->set_value("frequency","never");
 
         $user->set_value("frequency","never");
 
     }
 
     }
 +
    ## NEW: set default language to the session language
 
     if( !$user -> is_set( "lang" ) )
 
     if( !$user -> is_set( "lang" ) )
 
     {
 
     {
Line 36: Line 37:
 
       <title><epc:phrase ref="user_section_personal" /></title>
 
       <title><epc:phrase ref="user_section_personal" /></title>
 
       <field ref="name" required="yes" />
 
       <field ref="name" required="yes" />
       <field ref="lang"/> &lt;-- NEW!!! --&gt;
+
       <field ref="lang"/> &lt;-- NEW!!! edit preferred language --&gt;
 
       <field ref="dept"/>
 
       <field ref="dept"/>
 
       <field ref="org"/>
 
       <field ref="org"/>
Line 44: Line 45:
 
     </component>
 
     </component>
  
 +
Finally, you might want the default language appear on the user's profile pages. This needs editing the cfg/cfg.d/user_render.pl file by inserting the following into the place of your choice (I coose just next to "country"):
  
 +
  if( $user->is_set( "lang" ) )
 +
  {
 +
      $p->appendChild($session->>make_element( "br" ) );
 +
      $p->appendChild($session->html_phrase("user_default_language",
 +
                lang => $user->render_value( "lang" ) ) );
 +
  }
 +
 +
here the new phrase "user_default_language" should be defined in one of the phrases files; in it the pin "lang" contains the language itself:
 +
 +
  &lt;epp:phrase id="user_default_language"&gt;Default language:
 +
      &lt; epc_pin name="lang"/&gt;
 +
  &lt;/epp:phrase&gt;
  
 
== Phrases ==
 
== Phrases ==

Revision as of 13:04, 27 June 2007

Making translation to Eprints3 is similar to that of earlier versions. Here only some of the differences are pointed out. Also, there is a difference between just translating, or making a multilingual site. If you are making a translation, then with little effort you can also make your site speak English too, a courtesy for casual visitors of your repository.

Considerations for multilingual sites

In a multilingual site you probably let the visitors to choose the language of the session. It is determined by the default setting of the browser preferences, but sometimes users want to change this. Manual setting of the session's language can be done by the [port] of the set_language script from earlier Eprints versions, and should go into the cgi directory. A handy place for the set_language URL is in the menu at the top of the page. You might want to edit lib/defaultcfg/lang/en/templates/default.xml to include this possibility there:

 <ul class="ep_tm_menu">
  <li><a href="{$config{frontpage}}">Home</a></li>
  <li><a ref="{$config{perl_url}}/set_lang">Language</a></li>
   <li><a href="{$config{base_url}}/information.html">About</a></li>
  ... 
 </ul>

The template page on other languages should not contain this Language item as not neccessarily will people recognise it. Rather use a button which goes back to the standard English":

  <li><a href="{$config{perl_url}/set_lang?langid=en">In English</a></li>

By default, all e-mail messages are sent out on the default language of the depository. You might let users choose their preferred language so that they'll receive messages on that language. The lang (system) field is defined for all users; the value can be set automatically in defaultcfg/cfg.d/user_fields_automatic.pl for example by

$c->{set_user_automatic_fields} = sub
{ my ( $user ) = @_;
   if( !$user -> is_set( "frequency" ) )
  {
        $user->set_value("frequency","never");
   }
   ## NEW: set default language to the session language
   if( !$user -> is_set( "lang" ) )
   {
        $user->set_value("lang",$user->{session}->{lang}->{id});
   }
}

and also let the user edit their own preference by inserting the lang field in the defaultcfg/workflows/user/default.xml workflow, say in the personal section:

  <component type="Field::Multi">
     <title><epc:phrase ref="user_section_personal" /></title>
     <field ref="name" required="yes" />
     <field ref="lang"/> <-- NEW!!! edit preferred language -->
     <field ref="dept"/>
     <field ref="org"/>
     <field ref="address"/>
     <field ref="country"/>
     <field ref="url"/>
   </component>

Finally, you might want the default language appear on the user's profile pages. This needs editing the cfg/cfg.d/user_render.pl file by inserting the following into the place of your choice (I coose just next to "country"):

 if( $user->is_set( "lang" ) )
 {
      $p->appendChild($session->>make_element( "br" ) );
      $p->appendChild($session->html_phrase("user_default_language",
                lang => $user->render_value( "lang" ) ) );
 }

here the new phrase "user_default_language" should be defined in one of the phrases files; in it the pin "lang" contains the language itself:

 <epp:phrase id="user_default_language">Default language: 
      < epc_pin name="lang"/>
 </epp:phrase>

Phrases

Other configuration files

Subject list

Patches

Apart from translating the language dependent phrase files, some other modification might be useful for a multilanguage repository:

  • user names could be rendered depending on the language
  • expiration time for the pin codes (e.g. when registering)
  • generation time for the browse pages
  • proper utf-8 encoding for outgoing e-mails

Here are some ideas what to do.

Rendering user names

All fields can have their separate rendering routine. This routine should be given as the value of the render_single_value attribute. In our case modify the top of cfg.d/user_fields.pl file which contains the definition of the user fields as follows:

 $c->{fields}->{user} = [
     {
         'name' => 'name',
         'type'   => 'name',
         'render_order' => 'gf',
         'render_single_value' => \&my_namefield_rendering,
     },
     ...

and insert the definition of my_namefield_rendering e.g. at the end of the same file:

sub my_namefield_rendering
{
   my ($session,$field,$value,$object)=@_;
   my $langid = $session->{lang}->{id}; 
   my $format = {
# format: f, g - first, given; h - honourific, l - lineage
     'en' => 'hfl,g',
     'hu' => 'hlfg',
# Further lines should be added for other used languages
   } -> {$langid}
   my $all="";
   foreach my $fmtchar ( split //, $format ) {
       my $insert="";
       if( $fmtchar eq "l" ) {$insert = $value->{lineage}; }
       elsif( $fmtchar eq "f" ) { $insert = $value->{family}; }
       elsif( $fmtchar eq "g" ) { $insert = $value->{given}; }
       elsif( $fmtchar eq "h" ) { $insert = $value->{honourific}; }
       elsif( $all ){ $all .= $fmtchar; }
       next if( ! $insert );
       $all .= $insert;
   }
   my $span=$session->make_element("span",class=>"person_name");
   $span->appendChild($session->make_text($all));
   $return $span;
}

Indexing