Difference between revisions of "API:EPrints/Language"

From EPrints Documentation
Jump to: navigation, search
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
<!-- Pod2Wiki=_preamble_  
 
<!-- Pod2Wiki=_preamble_  
This page has been automatically generated from the EPrints 3.2 source. Any wiki changes made between the 'Pod2Wiki=*' and 'Edit below this comment' comments will be lost.
+
This page has been automatically generated from the EPrints 3.4 source. Any wiki changes made between the 'Pod2Wiki=*' and 'Edit below this comment' comments will be lost.
  -->{{API}}{{Pod2Wiki}}{{API:Source|file=perl_lib/EPrints/Language.pm|package_name=EPrints::Language}}[[Category:API|LANGUAGE]][[Category:API:EPrints/Language|LANGUAGE]]<div><!-- Edit below this comment -->
+
  -->{{API}}{{Pod2Wiki}}{{API:Source|file=EPrints/Language.pm|package_name=EPrints::Language}}[[Category:API|LANGUAGE]]<div><!-- Edit below this comment -->
  
  
Line 26: Line 26:
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
 
</div>
 
</div>
<!-- Pod2Wiki=head_methods -->
+
<!-- Pod2Wiki=head_instance_variables -->
==METHODS==
+
==INSTANCE VARIABLES==
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<span style='display:none'>User Comments</span>
 
<span style='display:none'>User Comments</span>
Line 35: Line 35:
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
 
</div>
 
</div>
<!-- Pod2Wiki=item_new -->
+
<!-- Pod2Wiki=item_$self->{id} -->
===new===
+
===$self-&gt;{id}===
 +
 
 +
The ISO ID of this language.
 +
 
 +
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 +
<span style='display:none'>User Comments</span>
 +
<!-- Edit below this comment -->
 +
 
  
$language = EPrints::Language-&gt;new( $langid, $repository, [$fallback] )
+
<!-- Pod2Wiki= -->
Create a new language object representing the phases eprints will use in a given language, loading them from the phrase config XML files.
+
</div>
 +
<!-- Pod2Wiki=item_$self->{fallback} -->
 +
===$self-&gt;{fallback}===
  
$langid is the ISO language ID of the language, $repository is the repository to which this language object belongs. $fallback is either undef or a reference to the main language object for the repository.
+
If $self is the primary language in its repository then this is  <tt>undef</tt>, otherwise it is a reference to the primary language object.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 50: Line 59:
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
 
</div>
 
</div>
<!-- Pod2Wiki=item_get_phrase_info -->
+
<!-- Pod2Wiki=item_$self->{repository_data} -->
===get_phrase_info===
+
===$self-&gt;{repository_data}===
 
 
$info = $lang-&gt;get_phrase_info( $phraseid, $session )
 
Returns a hash describing the phrase $phraseid. Contains:
 
  
  langid - the language the phrase is from
+
A reference to a hash. Keys are IDs for phrases, values are DOM  fragments containing the phases. Contains repository specific  phrases.
  phraseid - the phrase id
 
  xml - the raw XML fragment
 
  fallback - whether the phrase was from the fallback language
 
  system - whether the phrase was from the system files
 
  filename - the file the phrase came from
 
 
 
If $phraseid doesn't exist returns undef.
 
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 72: Line 71:
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
 
</div>
 
</div>
<!-- Pod2Wiki=item_get_phrase_ids -->
+
<!-- Pod2Wiki=item_$self->{data} -->
===get_phrase_ids===
+
===$self-&gt;{data}===
 
 
$phraseids = $language-&gt;get_phrase_ids( $fallback )
 
Return a reference to an array of all phrase ids that are defined in this language (repository and system).
 
  
If $fallback is true returns any additional phrase ids defined in the fallback language.
+
A reference to a hash. Keys are IDs for phrases, values are DOM  fragments containing the phases. Contains generic eprints phrases.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 87: Line 83:
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
 
</div>
 
</div>
<!-- Pod2Wiki=item_phrase -->
+
<!-- Pod2Wiki=item_$self->{xmldoc} -->
===phrase===
+
===$self-&gt;{xmldoc}===
 +
 
 +
A XML document to hold all the stray DOM elements.
  
  $xhtml = $language-&gt;phrase( $phraseid, $inserts, $session )
+
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '>
Return an XHTML DOM structure for the phrase with the given phraseid.
+
<span style='display:none'>User Comments</span>
 +
<!-- Edit below this comment -->
  
The phraseid is looked for in the following order, if it's not in one phrase file the system checks the next.
 
  
 +
<!-- Pod2Wiki= -->
 +
</div>
 +
<!-- Pod2Wiki=head_methods -->
 +
==METHODS==
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<span style='display:none'>User Comments</span>
 
<span style='display:none'>User Comments</span>
Line 102: Line 104:
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
 
</div>
 
</div>
<!-- Pod2Wiki=item_this_languages_repository_specific_phrases -->
+
<!-- Pod2Wiki=item_new -->
===this_languages_repository_specific_phrases===
+
===new===
 +
 
 +
$language = EPrints::Language-&gt;new( $langid, $repository, [ $fallback ] )
 +
Create a new language object representing the phases eprints will use in a given language, loading them from the phrase config XML files.
 +
 
 +
<tt>$langid</tt> is the ISO language ID of the language, <tt>$repository</tt> is  the repository to which this language object belongs. <tt>$fallback</tt> is  either <tt>undef</tt> or a reference to the main language object for the  repository.
  
This languages repository specific phrases.
 
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<span style='display:none'>User Comments</span>
 
<span style='display:none'>User Comments</span>
Line 113: Line 119:
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
 
</div>
 
</div>
<!-- Pod2Wiki=item_phrases -->
+
<!-- Pod2Wiki=item_clone -->
===phrases===
+
===clone===
 +
 
 +
EPrints::Language-&gt;CLONE
 +
Clone a language object.
  
The fallback languages repository specific phrases (if there is a fallback).
 
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<span style='display:none'>User Comments</span>
 
<span style='display:none'>User Comments</span>
Line 124: Line 132:
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
 
</div>
 
</div>
<!-- Pod2Wiki=item_this_languages_general_phrases -->
+
<!-- Pod2Wiki=item_get_phrase_info -->
===this_languages_general_phrases===
+
===get_phrase_info===
 +
 
 +
$info = $language-&gt;get_phrase_info( $phraseid )
 +
Returns a hash describing the phrase <tt>$phraseid</tt>. Contains:
 +
 
 +
langid - the language the phrase is from
 +
phraseid - the phrase ID
 +
xml - the raw XML fragment
 +
fallback - whether the phrase was from the fallback language
 +
system - whether the phrase was from the system files
 +
filename - the file the phrase came from
 +
 
 +
If <tt>$phraseid</tt> doesn't exist returns <tt>undef</tt>.
  
This languages general phrases.
 
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<span style='display:none'>User Comments</span>
 
<span style='display:none'>User Comments</span>
Line 135: Line 154:
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
 
</div>
 
</div>
<!-- Pod2Wiki=item_phrases -->
+
<!-- Pod2Wiki=item_get_phrase_ids -->
===phrases===
+
===get_phrase_ids===
 +
 
 +
$phraseids = $language-&gt;get_phrase_ids( $fallback )
 +
Returns a reference to an array of all phrase ids that are defined in  this language (repository and system).
 +
 
 +
If <tt>$fallback</tt> is <tt>true</tt> returns any additional phrase IDs defined  in the fallback language.
  
The fallback languages general phrases (if there is a fallback).
 
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<span style='display:none'>User Comments</span>
 
<span style='display:none'>User Comments</span>
Line 146: Line 169:
 
<!-- Pod2Wiki= -->
 
<!-- Pod2Wiki= -->
 
</div>
 
</div>
<!-- Pod2Wiki=item_failing_that_it_returns_an_xhtml_dom_encoded_error -->
+
<!-- Pod2Wiki=item_phrase -->
===failing_that_it_returns_an_xhtml_dom_encoded_error===
+
===phrase===
 +
 
 +
$xhtml = $language-&gt;phrase( $phraseid, $inserts )
 +
Return an XHTML DOM structure for the phrase with the given phraseid.
 +
 
 +
The <tt>$phraseid</tt> is looked for in the following order, if it's not in one phrase file the system checks the next.
 +
 
 +
1. This languages repository specific phrases.
 +
 
 +
2. The fallback languages repository specific phrases (if there is a  fallback).
 +
 
 +
3. This languages general phrases.
 +
 
 +
4. The fallback languages general phrases (if there is a fallback).
 +
 
 +
5. Failing that it returns an XHTML DOM encoded error.
 +
 
 +
If the phrase contains <tt>pin</tt> elements then $inserts must be a  reference to a hash. Each <tt>pin</tt> has a <tt>name</tt> attribute. For each  pin there must be a key in <tt>$inserts</tt> of the <tt>name</tt>. The value is a  XHTML DOM object which will replace the <tt>pin</tt> when returing this  phrase.
  
Failing that it returns an XHTML DOM encoded error.
 
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<span style='display:none'>User Comments</span>
 
<span style='display:none'>User Comments</span>
Line 160: Line 199:
 
===has_phrase===
 
===has_phrase===
  
  $boolean = $language-&gt;has_phrase( $phraseid, $session )
+
  $boolean = $language-&gt;has_phrase( $phraseid )
Return 1 if the phraseid is defined for this language. Return 0 if it is only available as a fallback or unavailable.
+
Returns <tt>true</tt> if the <tt>$phraseid</tt> is defined for this language. Returns <tt>false</tt> if it is only available as a fallback or unavailable.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 186: Line 225:
 
===get_fallback===
 
===get_fallback===
  
  $lang = $language-&gt;get_fallback()
+
  $lang = $language-&gt;get_fallback
Return the fallback language for this language. Returns undef if there is no fallback.
+
Return the fallback language for this language. Returns <tt>undef</tt> if there is no fallback.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 199: Line 238:
 
===load_phrases===
 
===load_phrases===
  
  $ok = $language-&gt;load_phrases( $session, $file )
+
  $ok = $language-&gt;load_phrases( $file )
Load phrases from $file into the current language (use with care!).
+
Load phrases from <tt>$file</tt> into the current language. Use with care!
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 213: Line 252:
  
 
  $doc = EPrints::Language-&gt;create_phrase_doc( $session, [ $comment ] )
 
  $doc = EPrints::Language-&gt;create_phrase_doc( $session, [ $comment ] )
Create and return a new, empty, phrases document. Optionally put $comment at the top.
+
Create and return a new, empty, phrases document. Optionally put <tt>$comment</tt> at the top.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 224: Line 263:
 
<!-- Pod2Wiki=head_copyright -->
 
<!-- Pod2Wiki=head_copyright -->
 
==COPYRIGHT==
 
==COPYRIGHT==
 +
{{API:Copyright}}
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<span style='display:none'>User Comments</span>
 
<span style='display:none'>User Comments</span>

Latest revision as of 00:43, 12 January 2022

EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects


API: Core API

Latest Source Code (3.4, 3.3) | Revision Log | Before editing this page please read Pod2Wiki


NAME

EPrints::Language - A Single Language supported by a repository.

User Comments


DESCRIPTION

The language class handles loading the "phrase" files for a single language. See the mail documentation for a full explanation of the format of phrase files.

User Comments


INSTANCE VARIABLES

User Comments


$self->{id}

The ISO ID of this language.

User Comments


$self->{fallback}

If $self is the primary language in its repository then this is undef, otherwise it is a reference to the primary language object.

User Comments


$self->{repository_data}

A reference to a hash. Keys are IDs for phrases, values are DOM fragments containing the phases. Contains repository specific phrases.

User Comments


$self->{data}

A reference to a hash. Keys are IDs for phrases, values are DOM fragments containing the phases. Contains generic eprints phrases.

User Comments


$self->{xmldoc}

A XML document to hold all the stray DOM elements.

User Comments


METHODS

User Comments


new

$language = EPrints::Language->new( $langid, $repository, [ $fallback ] )

Create a new language object representing the phases eprints will use in a given language, loading them from the phrase config XML files.

$langid is the ISO language ID of the language, $repository is the repository to which this language object belongs. $fallback is either undef or a reference to the main language object for the repository.

User Comments


clone

EPrints::Language->CLONE

Clone a language object.

User Comments


get_phrase_info

$info = $language->get_phrase_info( $phraseid )

Returns a hash describing the phrase $phraseid. Contains:

langid - the language the phrase is from
phraseid - the phrase ID
xml - the raw XML fragment
fallback - whether the phrase was from the fallback language
system - whether the phrase was from the system files
filename - the file the phrase came from
 

If $phraseid doesn't exist returns undef.

User Comments


get_phrase_ids

$phraseids = $language->get_phrase_ids( $fallback )

Returns a reference to an array of all phrase ids that are defined in this language (repository and system).

If $fallback is true returns any additional phrase IDs defined in the fallback language.

User Comments


phrase

$xhtml = $language->phrase( $phraseid, $inserts )

Return an XHTML DOM structure for the phrase with the given phraseid.

The $phraseid is looked for in the following order, if it's not in one phrase file the system checks the next.

1. This languages repository specific phrases.

2. The fallback languages repository specific phrases (if there is a fallback).

3. This languages general phrases.

4. The fallback languages general phrases (if there is a fallback).

5. Failing that it returns an XHTML DOM encoded error.

If the phrase contains pin elements then $inserts must be a reference to a hash. Each pin has a name attribute. For each pin there must be a key in $inserts of the name. The value is a XHTML DOM object which will replace the pin when returing this phrase.

User Comments


has_phrase

$boolean = $language->has_phrase( $phraseid )

Returns true if the $phraseid is defined for this language. Returns false if it is only available as a fallback or unavailable.

User Comments


get_id

$langid = $language->get_id

Return the ISO language ID of this language object.

User Comments


get_fallback

$lang = $language->get_fallback

Return the fallback language for this language. Returns undef if there is no fallback.

User Comments


load_phrases

$ok = $language->load_phrases( $file )

Load phrases from $file into the current language. Use with care!

User Comments


create_phrase_doc

$doc = EPrints::Language->create_phrase_doc( $session, [ $comment ] )

Create and return a new, empty, phrases document. Optionally put $comment at the top.

User Comments


COPYRIGHT

© Copyright 2000-2024 University of Southampton.

EPrints 3.4 is supplied by EPrints Services.

http://www.eprints.org/eprints-3.4/

LICENSE

This file is part of EPrints 3.4 http://www.eprints.org/.

EPrints 3.4 and this file are released under the terms of the GNU Lesser General Public License version 3 as published by the Free Software Foundation unless otherwise stated.

EPrints 3.4 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with EPrints 3.4. If not, see http://www.gnu.org/licenses/.

User Comments