<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.eprints.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mamalos%40eng.auth.gr</id>
	<title>EPrints Documentation - User contributions [en-gb]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.eprints.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mamalos%40eng.auth.gr"/>
	<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/Special:Contributions/Mamalos@eng.auth.gr"/>
	<updated>2026-05-17T00:11:54Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.8</generator>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12131</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12131"/>
		<updated>2016-07-07T10:29:37Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Warning for already populated repositories */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''! The users of this plugin are requested to use EPrints API to copy the values from the old fields to the new ones. A script that copies the '''title''' value of each eprint to '''ml_title''' field's '''en''' and '''el''' languages can be found here:[https://github.com/mamalos/eprints/blob/master/help_scripts/set_ml_title.pl]. Please, use this script at your own risk and don't forget to change its content to reflect the languages of your repository. The same script can be used for copying the '''abstract''' field's values to '''ml_abstract''' '''en''' and '''el''' by replacing title with abstract in this script.&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. The last statements of our example code show how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value via its corresponding '''multilang''' field ('''ml_title'''). So, each new record now has a '''multilang''' field which it can access via the interface provided by the calculated field of type '''virtualwithvalue''', which is no other than EPrints' basic '''title''' field.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only a single value from the '''title''' (and '''abstract''') field, and '''multilang''' fields don't support such functionality. Hence, doing so would cause EPrints to throw errors. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for our '''title''' field (using the data stored in '''ml_title''' field) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish when overriding these functions, as long as their code return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In our example we update the phrases for the English and for the Greek languages ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. So, for the English language we can add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases can be added in file '''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new '''multilang''' should be added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
EPrints' search functionality is only aware of the '''title''' field, so its search mechanisms -which directly search EPrints' database- has no knowledge about '''ml_title'''. To address this, we should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We have chosen not to change EPrints' default search configuration files, in order not to affect future EPrints' upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12130</id>
		<title>MultiLang Fields Bazaar Package</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12130"/>
		<updated>2016-07-07T10:28:42Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:EPrints 3 Plugins]]&lt;br /&gt;
&lt;br /&gt;
The MultiLang plugins introduces multiple language support in EPrints fields. The specific plugin replaces the '''title''' and '''abstract''' fields' types with their multilingual versions that calculate their values based on two newly added multilingual fields ('''ml_title''' and '''ml_abstract''' respectively). The wiki-page that explains how one can replace basic EPrints fields with multilang-fields -which basically explains how this plugin was created- is [[Adding multilang fields]]. &lt;br /&gt;
&lt;br /&gt;
== Installation Prerequisites ==&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Install through the EPrints Bazaar.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once this plugin is installed, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''! The users of this plugin are requested to use EPrints API to copy the values from the old fields to the new ones. A script that copies the '''title''' value of each eprint to '''ml_title''' field's '''en''' and '''el''' languages can be found here:[https://github.com/mamalos/eprints/blob/master/help_scripts/set_ml_title.pl]. Please, use this script at your own risk and don't forget to change its content to reflect the languages of your repository. The same script can be used for copying the '''abstract''' field's values to '''ml_abstract''' '''en''' and '''el''' by replacing title with abstract in this script.&lt;br /&gt;
&lt;br /&gt;
== How to use the plugin ==&lt;br /&gt;
Once the plugin has been installed, the user needs to edit the workflow to contain the multilingual fields' versions instead of the default ones. This procedure is explained in the next section.&lt;br /&gt;
&lt;br /&gt;
== Editing the workflow ==&lt;br /&gt;
In order for the plugin to be usable, the default field versions need to be commented out and the new multilingual ones need to be added. So, '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' has to be edited as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports the new '''ml_'''fields. Once the workflow has changed, the repository needs to be reloaded for the changes to take effect:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./epadmin reload reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Editing the phrase files ==&lt;br /&gt;
The plugin updates the EPrints system by providing an English and a Greek phrase file for the new fields it creates. The new fields are named '''ml_title''' and '''ml_abstract'''. So, if this plugin is used for repositories in other languages than these, the site administrator needs to provide the appropriate phrase files for their languages manually. What they can do is copy the phrases from the English language phrase file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/lang/en/phrases/local.xml''' and copy them to a new file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/lang/&amp;lt;your_lang&amp;gt;/phrases/'''. The file-name should have an '''xml''' extension (like '''local.xml''' in our example).&lt;br /&gt;
&lt;br /&gt;
The phrases that need to be added are the following (excerpt from the Greek phrases file):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- multilang title related phrases --&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- multilang abstract related phrases --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract&amp;quot;&amp;gt;Περίληψη&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_abstract&amp;quot;&amp;gt;Μία περίληψη των περιεχομένων. Εάν το τεκμήριο διαθέτει περίληψη, αυτή πρέπει να τοποθετηθεί εδώ. Υποστηρίζεται μόνον απλό κείμενο.&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How the plugin works ==&lt;br /&gt;
Basically, what the plugin does is that it replaces EPrints default '''title''' and '''abstract''' field types with a type that supports storing and retrieving information on multilingual fields. The procedure that we followed in order to achieve this functionality was the following:&lt;br /&gt;
&lt;br /&gt;
* We introduced a new field's type, '''virtualwithvalue''', that would allow our fields to override EPrints fields' default behaviour.&lt;br /&gt;
* We added multilingual versions of the fields that are replaced (namely '''ml_title''' and '''ml_abstract''') to store multilingual content.&lt;br /&gt;
* We introduced our new fields' names, types and functionality to EPrints via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''&lt;br /&gt;
* We added the appropriate phrases in each language's phrase file.&lt;br /&gt;
* We added a custom lookup cgi script that uses the new '''ml_title''' field for the autocompletion feature.&lt;br /&gt;
* We changed EPrints basic and advanced search scripts to search our new multilingual fields instead of the original ones.&lt;br /&gt;
&lt;br /&gt;
A screenshot showing how the two fields look when inserting a new document follows:&lt;br /&gt;
[[File:ruomo_multilang.jpg]]&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12129</id>
		<title>MultiLang Fields Bazaar Package</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12129"/>
		<updated>2016-07-07T10:28:09Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Warning for already populated repositories */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:EPrints 3 Plugins]]&lt;br /&gt;
&lt;br /&gt;
The MultiLang plugins introduces multiple language support in EPrints fields. The specific plugin replaces the '''title''' and '''abstract''' fields' types with their multilingual versions that calculate their values based on two newly added multilingual fields ('''ml_title''' and '''ml_abstract''' respectively). The wiki-page that explains how one can replace basic EPrints fields with multilang-fields -which basically explains how this plugin was created- is [[Adding multilang fields]]. &lt;br /&gt;
&lt;br /&gt;
== Installation Prerequisites ==&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Install through the EPrints Bazaar.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once this plugin is installed, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''! The users of this plugin are requested to use EPrints API to copy the values from the old fields to the new ones.&lt;br /&gt;
&lt;br /&gt;
== How to use the plugin ==&lt;br /&gt;
Once the plugin has been installed, the user needs to edit the workflow to contain the multilingual fields' versions instead of the default ones. This procedure is explained in the next section. A script that copies the '''title''' value of each eprint to '''ml_title''' field's '''en''' and '''el''' languages can be found here:[https://github.com/mamalos/eprints/blob/master/help_scripts/set_ml_title.pl]. Please, use this script at your own risk and don't forget to change its content to reflect the languages of your repository. The same script can be used for copying the '''abstract''' field's values to '''ml_abstract''' '''en''' and '''el''' by replacing title with abstract in this script.&lt;br /&gt;
&lt;br /&gt;
== Editing the workflow ==&lt;br /&gt;
In order for the plugin to be usable, the default field versions need to be commented out and the new multilingual ones need to be added. So, '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' has to be edited as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports the new '''ml_'''fields. Once the workflow has changed, the repository needs to be reloaded for the changes to take effect:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./epadmin reload reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Editing the phrase files ==&lt;br /&gt;
The plugin updates the EPrints system by providing an English and a Greek phrase file for the new fields it creates. The new fields are named '''ml_title''' and '''ml_abstract'''. So, if this plugin is used for repositories in other languages than these, the site administrator needs to provide the appropriate phrase files for their languages manually. What they can do is copy the phrases from the English language phrase file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/lang/en/phrases/local.xml''' and copy them to a new file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/lang/&amp;lt;your_lang&amp;gt;/phrases/'''. The file-name should have an '''xml''' extension (like '''local.xml''' in our example).&lt;br /&gt;
&lt;br /&gt;
The phrases that need to be added are the following (excerpt from the Greek phrases file):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- multilang title related phrases --&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- multilang abstract related phrases --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract&amp;quot;&amp;gt;Περίληψη&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_abstract&amp;quot;&amp;gt;Μία περίληψη των περιεχομένων. Εάν το τεκμήριο διαθέτει περίληψη, αυτή πρέπει να τοποθετηθεί εδώ. Υποστηρίζεται μόνον απλό κείμενο.&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How the plugin works ==&lt;br /&gt;
Basically, what the plugin does is that it replaces EPrints default '''title''' and '''abstract''' field types with a type that supports storing and retrieving information on multilingual fields. The procedure that we followed in order to achieve this functionality was the following:&lt;br /&gt;
&lt;br /&gt;
* We introduced a new field's type, '''virtualwithvalue''', that would allow our fields to override EPrints fields' default behaviour.&lt;br /&gt;
* We added multilingual versions of the fields that are replaced (namely '''ml_title''' and '''ml_abstract''') to store multilingual content.&lt;br /&gt;
* We introduced our new fields' names, types and functionality to EPrints via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''&lt;br /&gt;
* We added the appropriate phrases in each language's phrase file.&lt;br /&gt;
* We added a custom lookup cgi script that uses the new '''ml_title''' field for the autocompletion feature.&lt;br /&gt;
* We changed EPrints basic and advanced search scripts to search our new multilingual fields instead of the original ones.&lt;br /&gt;
&lt;br /&gt;
A screenshot showing how the two fields look when inserting a new document follows:&lt;br /&gt;
[[File:ruomo_multilang.jpg]]&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12128</id>
		<title>MultiLang Fields Bazaar Package</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12128"/>
		<updated>2016-07-07T10:25:22Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* How to use the plugin */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:EPrints 3 Plugins]]&lt;br /&gt;
&lt;br /&gt;
The MultiLang plugins introduces multiple language support in EPrints fields. The specific plugin replaces the '''title''' and '''abstract''' fields' types with their multilingual versions that calculate their values based on two newly added multilingual fields ('''ml_title''' and '''ml_abstract''' respectively). The wiki-page that explains how one can replace basic EPrints fields with multilang-fields -which basically explains how this plugin was created- is [[Adding multilang fields]]. &lt;br /&gt;
&lt;br /&gt;
== Installation Prerequisites ==&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Install through the EPrints Bazaar.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once this plugin is installed, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''! The users are requested to use EPrints API to copy the values from the old fields to the new ones.&lt;br /&gt;
&lt;br /&gt;
== How to use the plugin ==&lt;br /&gt;
Once the plugin has been installed, the user needs to edit the workflow to contain the multilingual fields' versions instead of the default ones. This procedure is explained in the next section. A script that copies the '''title''' value of each eprint to '''ml_title''' field's '''en''' and '''el''' languages can be found here:[https://github.com/mamalos/eprints/blob/master/help_scripts/set_ml_title.pl]. Please, use this script at your own risk and don't forget to change its content to reflect the languages of your repository. The same script can be used for copying the '''abstract''' field's values to '''ml_abstract''' '''en''' and '''el''' by replacing title with abstract in this script.&lt;br /&gt;
&lt;br /&gt;
== Editing the workflow ==&lt;br /&gt;
In order for the plugin to be usable, the default field versions need to be commented out and the new multilingual ones need to be added. So, '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' has to be edited as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports the new '''ml_'''fields. Once the workflow has changed, the repository needs to be reloaded for the changes to take effect:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./epadmin reload reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Editing the phrase files ==&lt;br /&gt;
The plugin updates the EPrints system by providing an English and a Greek phrase file for the new fields it creates. The new fields are named '''ml_title''' and '''ml_abstract'''. So, if this plugin is used for repositories in other languages than these, the site administrator needs to provide the appropriate phrase files for their languages manually. What they can do is copy the phrases from the English language phrase file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/lang/en/phrases/local.xml''' and copy them to a new file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/lang/&amp;lt;your_lang&amp;gt;/phrases/'''. The file-name should have an '''xml''' extension (like '''local.xml''' in our example).&lt;br /&gt;
&lt;br /&gt;
The phrases that need to be added are the following (excerpt from the Greek phrases file):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- multilang title related phrases --&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- multilang abstract related phrases --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract&amp;quot;&amp;gt;Περίληψη&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_abstract&amp;quot;&amp;gt;Μία περίληψη των περιεχομένων. Εάν το τεκμήριο διαθέτει περίληψη, αυτή πρέπει να τοποθετηθεί εδώ. Υποστηρίζεται μόνον απλό κείμενο.&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How the plugin works ==&lt;br /&gt;
Basically, what the plugin does is that it replaces EPrints default '''title''' and '''abstract''' field types with a type that supports storing and retrieving information on multilingual fields. The procedure that we followed in order to achieve this functionality was the following:&lt;br /&gt;
&lt;br /&gt;
* We introduced a new field's type, '''virtualwithvalue''', that would allow our fields to override EPrints fields' default behaviour.&lt;br /&gt;
* We added multilingual versions of the fields that are replaced (namely '''ml_title''' and '''ml_abstract''') to store multilingual content.&lt;br /&gt;
* We introduced our new fields' names, types and functionality to EPrints via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''&lt;br /&gt;
* We added the appropriate phrases in each language's phrase file.&lt;br /&gt;
* We added a custom lookup cgi script that uses the new '''ml_title''' field for the autocompletion feature.&lt;br /&gt;
* We changed EPrints basic and advanced search scripts to search our new multilingual fields instead of the original ones.&lt;br /&gt;
&lt;br /&gt;
A screenshot showing how the two fields look when inserting a new document follows:&lt;br /&gt;
[[File:ruomo_multilang.jpg]]&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12114</id>
		<title>MultiLang Fields Bazaar Package</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12114"/>
		<updated>2016-06-24T09:58:16Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Editing the phrase files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:EPrints 3 Plugins]]&lt;br /&gt;
&lt;br /&gt;
The MultiLang plugins introduces multiple language support in EPrints fields. The specific plugin replaces the '''title''' and '''abstract''' fields' types with their multilingual versions that calculate their values based on two newly added multilingual fields ('''ml_title''' and '''ml_abstract''' respectively). The wiki-page that explains how one can replace basic EPrints fields with multilang-fields -which basically explains how this plugin was created- is [[Adding multilang fields]]. &lt;br /&gt;
&lt;br /&gt;
== Installation Prerequisites ==&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Install through the EPrints Bazaar.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once this plugin is installed, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''! The users are requested to use EPrints API to copy the values from the old fields to the new ones.&lt;br /&gt;
&lt;br /&gt;
== How to use the plugin ==&lt;br /&gt;
Once the plugin has been installed, the user needs to edit the workflow to contain the multilingual fields' versions instead of the default ones. This procedure is explained in the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Editing the workflow ==&lt;br /&gt;
In order for the plugin to be usable, the default field versions need to be commented out and the new multilingual ones need to be added. So, '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' has to be edited as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports the new '''ml_'''fields. Once the workflow has changed, the repository needs to be reloaded for the changes to take effect:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./epadmin reload reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Editing the phrase files ==&lt;br /&gt;
The plugin updates the EPrints system by providing an English and a Greek phrase file for the new fields it creates. The new fields are named '''ml_title''' and '''ml_abstract'''. So, if this plugin is used for repositories in other languages than these, the site administrator needs to provide the appropriate phrase files for their languages manually. What they can do is copy the phrases from the English language phrase file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/lang/en/phrases/local.xml''' and copy them to a new file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/lang/&amp;lt;your_lang&amp;gt;/phrases/'''. The file-name should have an '''xml''' extension (like '''local.xml''' in our example).&lt;br /&gt;
&lt;br /&gt;
The phrases that need to be added are the following (excerpt from the Greek phrases file):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- multilang title related phrases --&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- multilang abstract related phrases --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract&amp;quot;&amp;gt;Περίληψη&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_abstract&amp;quot;&amp;gt;Μία περίληψη των περιεχομένων. Εάν το τεκμήριο διαθέτει περίληψη, αυτή πρέπει να τοποθετηθεί εδώ. Υποστηρίζεται μόνον απλό κείμενο.&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How the plugin works ==&lt;br /&gt;
Basically, what the plugin does is that it replaces EPrints default '''title''' and '''abstract''' field types with a type that supports storing and retrieving information on multilingual fields. The procedure that we followed in order to achieve this functionality was the following:&lt;br /&gt;
&lt;br /&gt;
* We introduced a new field's type, '''virtualwithvalue''', that would allow our fields to override EPrints fields' default behaviour.&lt;br /&gt;
* We added multilingual versions of the fields that are replaced (namely '''ml_title''' and '''ml_abstract''') to store multilingual content.&lt;br /&gt;
* We introduced our new fields' names, types and functionality to EPrints via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''&lt;br /&gt;
* We added the appropriate phrases in each language's phrase file.&lt;br /&gt;
* We added a custom lookup cgi script that uses the new '''ml_title''' field for the autocompletion feature.&lt;br /&gt;
* We changed EPrints basic and advanced search scripts to search our new multilingual fields instead of the original ones.&lt;br /&gt;
&lt;br /&gt;
A screenshot showing how the two fields look when inserting a new document follows:&lt;br /&gt;
[[File:ruomo_multilang.jpg]]&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12113</id>
		<title>MultiLang Fields Bazaar Package</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12113"/>
		<updated>2016-06-24T09:57:36Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Editing the phrase files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:EPrints 3 Plugins]]&lt;br /&gt;
&lt;br /&gt;
The MultiLang plugins introduces multiple language support in EPrints fields. The specific plugin replaces the '''title''' and '''abstract''' fields' types with their multilingual versions that calculate their values based on two newly added multilingual fields ('''ml_title''' and '''ml_abstract''' respectively). The wiki-page that explains how one can replace basic EPrints fields with multilang-fields -which basically explains how this plugin was created- is [[Adding multilang fields]]. &lt;br /&gt;
&lt;br /&gt;
== Installation Prerequisites ==&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Install through the EPrints Bazaar.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once this plugin is installed, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''! The users are requested to use EPrints API to copy the values from the old fields to the new ones.&lt;br /&gt;
&lt;br /&gt;
== How to use the plugin ==&lt;br /&gt;
Once the plugin has been installed, the user needs to edit the workflow to contain the multilingual fields' versions instead of the default ones. This procedure is explained in the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Editing the workflow ==&lt;br /&gt;
In order for the plugin to be usable, the default field versions need to be commented out and the new multilingual ones need to be added. So, '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' has to be edited as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports the new '''ml_'''fields. Once the workflow has changed, the repository needs to be reloaded for the changes to take effect:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./epadmin reload reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Editing the phrase files ==&lt;br /&gt;
The plugin updates the EPrints system by providing an English and a Greek phrase file for the new fields it creates. The new fields are named '''ml_title''' and '''ml_abstract'''. So, if this plugin is used for repositories in other languages than these, the site administrator needs to provide the appropriate phrase files for their languages manually. What they can do is copy the phrases from the English language phrase file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/lang/en/phrases/local.xml''' and copy them to a new file located in ~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/lang/&amp;lt;your_lang&amp;gt;/phrases/'''. The file-name should have an '''xml''' extension (like '''local.xml''' in our example).&lt;br /&gt;
&lt;br /&gt;
The phrases that need to be added are the following (excerpt from the Greek phrases file):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- multilang title related phrases --&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
        &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- multilang abstract related phrases --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract&amp;quot;&amp;gt;Περίληψη&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_abstract&amp;quot;&amp;gt;Μία περίληψη των περιεχομένων. Εάν το τεκμήριο διαθέτει περίληψη, αυτή πρέπει να τοποθετηθεί εδώ. Υποστηρίζεται μόνον απλό κείμενο.&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How the plugin works ==&lt;br /&gt;
Basically, what the plugin does is that it replaces EPrints default '''title''' and '''abstract''' field types with a type that supports storing and retrieving information on multilingual fields. The procedure that we followed in order to achieve this functionality was the following:&lt;br /&gt;
&lt;br /&gt;
* We introduced a new field's type, '''virtualwithvalue''', that would allow our fields to override EPrints fields' default behaviour.&lt;br /&gt;
* We added multilingual versions of the fields that are replaced (namely '''ml_title''' and '''ml_abstract''') to store multilingual content.&lt;br /&gt;
* We introduced our new fields' names, types and functionality to EPrints via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''&lt;br /&gt;
* We added the appropriate phrases in each language's phrase file.&lt;br /&gt;
* We added a custom lookup cgi script that uses the new '''ml_title''' field for the autocompletion feature.&lt;br /&gt;
* We changed EPrints basic and advanced search scripts to search our new multilingual fields instead of the original ones.&lt;br /&gt;
&lt;br /&gt;
A screenshot showing how the two fields look when inserting a new document follows:&lt;br /&gt;
[[File:ruomo_multilang.jpg]]&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12112</id>
		<title>MultiLang Fields Bazaar Package</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12112"/>
		<updated>2016-06-24T09:56:48Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Editing the phrase files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:EPrints 3 Plugins]]&lt;br /&gt;
&lt;br /&gt;
The MultiLang plugins introduces multiple language support in EPrints fields. The specific plugin replaces the '''title''' and '''abstract''' fields' types with their multilingual versions that calculate their values based on two newly added multilingual fields ('''ml_title''' and '''ml_abstract''' respectively). The wiki-page that explains how one can replace basic EPrints fields with multilang-fields -which basically explains how this plugin was created- is [[Adding multilang fields]]. &lt;br /&gt;
&lt;br /&gt;
== Installation Prerequisites ==&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Install through the EPrints Bazaar.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once this plugin is installed, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''! The users are requested to use EPrints API to copy the values from the old fields to the new ones.&lt;br /&gt;
&lt;br /&gt;
== How to use the plugin ==&lt;br /&gt;
Once the plugin has been installed, the user needs to edit the workflow to contain the multilingual fields' versions instead of the default ones. This procedure is explained in the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Editing the workflow ==&lt;br /&gt;
In order for the plugin to be usable, the default field versions need to be commented out and the new multilingual ones need to be added. So, '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' has to be edited as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports the new '''ml_'''fields. Once the workflow has changed, the repository needs to be reloaded for the changes to take effect:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./epadmin reload reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Editing the phrase files ==&lt;br /&gt;
The plugin updates the EPrints system by providing an English and a Greek phrase file for the new fields it creates. The new fields are named '''ml_title''' and '''ml_abstract'''. So, if this plugin is used for repositories in other languages than these, the site administrator needs to provide the appropriate phrase files for their languages manually. What they can do is copy the phrases from the English language phrase file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/lang/en/phrases/local.xml''' and copy them to a new file located in ~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/lang/&amp;lt;your_lang&amp;gt;/phrases/'''. The file-name should have an '''xml''' extension (like '''local.xml''' in our example).&lt;br /&gt;
&lt;br /&gt;
The phrases that need to be added are the following (excerpt from the Greek phrases file):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- multilang title related phrases --&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
&amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- multilang abstract related phrases --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract&amp;quot;&amp;gt;Περίληψη&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_abstract&amp;quot;&amp;gt;Μία περίληψη των περιεχομένων. Εάν το τεκμήριο διαθέτει περίληψη, αυτή πρέπει να τοποθετηθεί εδώ. Υποστηρίζεται μόνον απλό κείμενο.&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How the plugin works ==&lt;br /&gt;
Basically, what the plugin does is that it replaces EPrints default '''title''' and '''abstract''' field types with a type that supports storing and retrieving information on multilingual fields. The procedure that we followed in order to achieve this functionality was the following:&lt;br /&gt;
&lt;br /&gt;
* We introduced a new field's type, '''virtualwithvalue''', that would allow our fields to override EPrints fields' default behaviour.&lt;br /&gt;
* We added multilingual versions of the fields that are replaced (namely '''ml_title''' and '''ml_abstract''') to store multilingual content.&lt;br /&gt;
* We introduced our new fields' names, types and functionality to EPrints via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''&lt;br /&gt;
* We added the appropriate phrases in each language's phrase file.&lt;br /&gt;
* We added a custom lookup cgi script that uses the new '''ml_title''' field for the autocompletion feature.&lt;br /&gt;
* We changed EPrints basic and advanced search scripts to search our new multilingual fields instead of the original ones.&lt;br /&gt;
&lt;br /&gt;
A screenshot showing how the two fields look when inserting a new document follows:&lt;br /&gt;
[[File:ruomo_multilang.jpg]]&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12111</id>
		<title>MultiLang Fields Bazaar Package</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12111"/>
		<updated>2016-06-24T09:54:53Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:EPrints 3 Plugins]]&lt;br /&gt;
&lt;br /&gt;
The MultiLang plugins introduces multiple language support in EPrints fields. The specific plugin replaces the '''title''' and '''abstract''' fields' types with their multilingual versions that calculate their values based on two newly added multilingual fields ('''ml_title''' and '''ml_abstract''' respectively). The wiki-page that explains how one can replace basic EPrints fields with multilang-fields -which basically explains how this plugin was created- is [[Adding multilang fields]]. &lt;br /&gt;
&lt;br /&gt;
== Installation Prerequisites ==&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Install through the EPrints Bazaar.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once this plugin is installed, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''! The users are requested to use EPrints API to copy the values from the old fields to the new ones.&lt;br /&gt;
&lt;br /&gt;
== How to use the plugin ==&lt;br /&gt;
Once the plugin has been installed, the user needs to edit the workflow to contain the multilingual fields' versions instead of the default ones. This procedure is explained in the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Editing the workflow ==&lt;br /&gt;
In order for the plugin to be usable, the default field versions need to be commented out and the new multilingual ones need to be added. So, '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' has to be edited as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports the new '''ml_'''fields. Once the workflow has changed, the repository needs to be reloaded for the changes to take effect:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./epadmin reload reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Editing the phrase files ==&lt;br /&gt;
The plugin updates the EPrints system by providing an English and a Greek phrase for the new fields it creates. The new fields are named '''ml_title''' and '''ml_abstract'''. So, if this plugin is used for repositories in other languages than these, the site administrator needs to provide the phrases file for their language manually. What they can do is copy the phrases from the English language phrase-file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/lang/en/phrases/local.xml''' and copy them to a new file located in ~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/lang/&amp;lt;your_lang&amp;gt;/phrases/'''. The file-name should have an '''xml''' extension (like '''local.xml''' in our example).&lt;br /&gt;
&lt;br /&gt;
The phrases that need to be added are the following (excerpt from the Greek phrases file):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- multilang title related phrases --&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
&amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- multilang abstract related phrases --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract&amp;quot;&amp;gt;Περίληψη&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_abstract_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
    &amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_abstract&amp;quot;&amp;gt;Μία περίληψη των περιεχομένων. Εάν το τεκμήριο διαθέτει περίληψη, αυτή πρέπει να τοποθετηθεί εδώ. Υποστηρίζεται μόνον απλό κείμενο.&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How the plugin works ==&lt;br /&gt;
Basically, what the plugin does is that it replaces EPrints default '''title''' and '''abstract''' field types with a type that supports storing and retrieving information on multilingual fields. The procedure that we followed in order to achieve this functionality was the following:&lt;br /&gt;
&lt;br /&gt;
* We introduced a new field's type, '''virtualwithvalue''', that would allow our fields to override EPrints fields' default behaviour.&lt;br /&gt;
* We added multilingual versions of the fields that are replaced (namely '''ml_title''' and '''ml_abstract''') to store multilingual content.&lt;br /&gt;
* We introduced our new fields' names, types and functionality to EPrints via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''&lt;br /&gt;
* We added the appropriate phrases in each language's phrase file.&lt;br /&gt;
* We added a custom lookup cgi script that uses the new '''ml_title''' field for the autocompletion feature.&lt;br /&gt;
* We changed EPrints basic and advanced search scripts to search our new multilingual fields instead of the original ones.&lt;br /&gt;
&lt;br /&gt;
A screenshot showing how the two fields look when inserting a new document follows:&lt;br /&gt;
[[File:ruomo_multilang.jpg]]&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12110</id>
		<title>MultiLang Fields Bazaar Package</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12110"/>
		<updated>2016-06-24T09:44:54Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Warning for already populated repositories */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:EPrints 3 Plugins]]&lt;br /&gt;
&lt;br /&gt;
The MultiLang plugins introduces multiple language support in EPrints fields. The specific plugin replaces the '''title''' and '''abstract''' fields' types with their multilingual versions that calculate their values based on two newly added multilingual fields ('''ml_title''' and '''ml_abstract''' respectively). The wiki-page that explains how one can replace basic EPrints fields with multilang-fields -which basically explains how this plugin was created- is [[Adding multilang fields]]. &lt;br /&gt;
&lt;br /&gt;
== Installation Prerequisites ==&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Install through the EPrints Bazaar.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once this plugin is installed, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''! The users are requested to use EPrints API to copy the values from the old fields to the new ones.&lt;br /&gt;
&lt;br /&gt;
== How to use the plugin ==&lt;br /&gt;
Once the plugin has been installed, the user needs to edit the workflow to contain the multilingual fields' versions instead of the default ones. This procedure is explained in the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Editing the workflow ==&lt;br /&gt;
In order for the plugin to be usable, the default field versions need to be commented out and the new multilingual ones need to be added. So, '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' has to be edited as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports the new '''ml_'''fields. Once the workflow has changed, the repository needs to be reloaded for the changes to take effect:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./epadmin reload reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How the plugin works ==&lt;br /&gt;
Basically, what the plugin does is that it replaces EPrints default '''title''' and '''abstract''' field types with a type that supports storing and retrieving information on multilingual fields. The procedure that we followed in order to achieve this functionality was the following:&lt;br /&gt;
&lt;br /&gt;
* We introduced a new field's type, '''virtualwithvalue''', that would allow our fields to override EPrints fields' default behaviour.&lt;br /&gt;
* We added multilingual versions of the fields that are replaced (namely '''ml_title''' and '''ml_abstract''') to store multilingual content.&lt;br /&gt;
* We introduced our new fields' names, types and functionality to EPrints via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''&lt;br /&gt;
* We added the appropriate phrases in each language's phrase file.&lt;br /&gt;
* We added a custom lookup cgi script that uses the new '''ml_title''' field for the autocompletion feature.&lt;br /&gt;
* We changed EPrints basic and advanced search scripts to search our new multilingual fields instead of the original ones.&lt;br /&gt;
&lt;br /&gt;
A screenshot showing how the two fields look when inserting a new document follows:&lt;br /&gt;
[[File:ruomo_multilang.jpg]]&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=File:Ruomo_multilang.jpg&amp;diff=12106</id>
		<title>File:Ruomo multilang.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=File:Ruomo_multilang.jpg&amp;diff=12106"/>
		<updated>2016-06-18T07:15:59Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: Mamalos@eng.auth.gr uploaded a new version of &amp;amp;quot;File:Ruomo multilang.jpg&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=File:Ruomo_multilang.jpg&amp;diff=12105</id>
		<title>File:Ruomo multilang.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=File:Ruomo_multilang.jpg&amp;diff=12105"/>
		<updated>2016-06-18T07:13:39Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: Mamalos@eng.auth.gr uploaded a new version of &amp;amp;quot;File:Ruomo multilang.jpg&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=File:Ruomo_multilang.jpg&amp;diff=12104</id>
		<title>File:Ruomo multilang.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=File:Ruomo_multilang.jpg&amp;diff=12104"/>
		<updated>2016-06-18T07:12:23Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12084</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12084"/>
		<updated>2016-06-07T12:27:10Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Adding search support for the ml_title field */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. The last statements of our example code show how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value via its corresponding '''multilang''' field ('''ml_title'''). So, each new record now has a '''multilang''' field which it can access via the interface provided by the calculated field of type '''virtualwithvalue''', which is no other than EPrints' basic '''title''' field.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only a single value from the '''title''' (and '''abstract''') field, and '''multilang''' fields don't support such functionality. Hence, doing so would cause EPrints to throw errors. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for our '''title''' field (using the data stored in '''ml_title''' field) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish when overriding these functions, as long as their code return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In our example we update the phrases for the English and for the Greek languages ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. So, for the English language we can add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases can be added in file '''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new '''multilang''' should be added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
EPrints' search functionality is only aware of the '''title''' field, so its search mechanisms -which directly search EPrints' database- has no knowledge about '''ml_title'''. To address this, we should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We have chosen not to change EPrints' default search configuration files, in order not to affect future EPrints' upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12083</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12083"/>
		<updated>2016-06-07T12:26:39Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Adding search support for the ml_title field */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. The last statements of our example code show how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value via its corresponding '''multilang''' field ('''ml_title'''). So, each new record now has a '''multilang''' field which it can access via the interface provided by the calculated field of type '''virtualwithvalue''', which is no other than EPrints' basic '''title''' field.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only a single value from the '''title''' (and '''abstract''') field, and '''multilang''' fields don't support such functionality. Hence, doing so would cause EPrints to throw errors. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for our '''title''' field (using the data stored in '''ml_title''' field) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish when overriding these functions, as long as their code return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In our example we update the phrases for the English and for the Greek languages ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. So, for the English language we can add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases can be added in file '''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new '''multilang''' should be added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
EPrints' search functionality is only aware of the '''title''' field, so its search mechanisms -which directly search EPrints' database- has no knowledge about '''ml_title'''. To address this, we should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We have chosen not to change EPrints' default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12082</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12082"/>
		<updated>2016-06-07T12:26:06Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Adding search support for the ml_title field */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. The last statements of our example code show how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value via its corresponding '''multilang''' field ('''ml_title'''). So, each new record now has a '''multilang''' field which it can access via the interface provided by the calculated field of type '''virtualwithvalue''', which is no other than EPrints' basic '''title''' field.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only a single value from the '''title''' (and '''abstract''') field, and '''multilang''' fields don't support such functionality. Hence, doing so would cause EPrints to throw errors. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for our '''title''' field (using the data stored in '''ml_title''' field) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish when overriding these functions, as long as their code return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In our example we update the phrases for the English and for the Greek languages ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. So, for the English language we can add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases can be added in file '''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new '''multilang''' should be added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
EPrints' search functionality is only aware of the '''title''' field, so its search mechanisms -which directly search EPrints' database- has no knowledge about '''ml_title'''. To address this, we should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12081</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12081"/>
		<updated>2016-06-07T12:25:42Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Adding search support for the ml_title field */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. The last statements of our example code show how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value via its corresponding '''multilang''' field ('''ml_title'''). So, each new record now has a '''multilang''' field which it can access via the interface provided by the calculated field of type '''virtualwithvalue''', which is no other than EPrints' basic '''title''' field.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only a single value from the '''title''' (and '''abstract''') field, and '''multilang''' fields don't support such functionality. Hence, doing so would cause EPrints to throw errors. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for our '''title''' field (using the data stored in '''ml_title''' field) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish when overriding these functions, as long as their code return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In our example we update the phrases for the English and for the Greek languages ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. So, for the English language we can add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases can be added in file '''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new '''multilang''' should be added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
EPrints' search functionality is only aware of the '''title''' field, so its search mechanisms -which directly search EPrints' database- has no knowledge about '''ml_title'''. To address this, we should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database'''Bold text'''. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12080</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12080"/>
		<updated>2016-06-07T12:25:06Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Adding search support for the ml_title field */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. The last statements of our example code show how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value via its corresponding '''multilang''' field ('''ml_title'''). So, each new record now has a '''multilang''' field which it can access via the interface provided by the calculated field of type '''virtualwithvalue''', which is no other than EPrints' basic '''title''' field.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only a single value from the '''title''' (and '''abstract''') field, and '''multilang''' fields don't support such functionality. Hence, doing so would cause EPrints to throw errors. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for our '''title''' field (using the data stored in '''ml_title''' field) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish when overriding these functions, as long as their code return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In our example we update the phrases for the English and for the Greek languages ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. So, for the English language we can add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases can be added in file '''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new '''multilang''' should be added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
EPrints' search functionality is only aware about the '''title''' field, so its search mechanisms -which directly search EPrints' database- will not search within '''ml_title'''. To address this, we should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database'''Bold text'''. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12079</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12079"/>
		<updated>2016-06-07T12:22:21Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. The last statements of our example code show how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value via its corresponding '''multilang''' field ('''ml_title'''). So, each new record now has a '''multilang''' field which it can access via the interface provided by the calculated field of type '''virtualwithvalue''', which is no other than EPrints' basic '''title''' field.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only a single value from the '''title''' (and '''abstract''') field, and '''multilang''' fields don't support such functionality. Hence, doing so would cause EPrints to throw errors. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for our '''title''' field (using the data stored in '''ml_title''' field) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish when overriding these functions, as long as their code return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In our example we update the phrases for the English and for the Greek languages ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. So, for the English language we can add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases can be added in file '''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new '''multilang''' should be added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12078</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12078"/>
		<updated>2016-06-07T12:20:29Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Replacing the title field with ml_title field in the workflow */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. The last statements of our example code show how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value via its corresponding '''multilang''' field ('''ml_title'''). So, each new record now has a '''multilang''' field which it can access via the interface provided by the calculated field of type '''virtualwithvalue''', which is no other than EPrints' basic '''title''' field.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only a single value from the '''title''' (and '''abstract''') field, and '''multilang''' fields don't support such functionality. Hence, doing so would cause EPrints to throw errors. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for our '''title''' field (using the data stored in '''ml_title''' field) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish when overriding these functions, as long as their code return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In our example we update the phrases for the English and for the Greek languages ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. So, for the English language we can add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases can be added in file '''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new '''multilang''' should be added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12077</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12077"/>
		<updated>2016-06-07T12:19:49Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Adding the appropriate phrases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. The last statements of our example code show how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value via its corresponding '''multilang''' field ('''ml_title'''). So, each new record now has a '''multilang''' field which it can access via the interface provided by the calculated field of type '''virtualwithvalue''', which is no other than EPrints' basic '''title''' field.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only a single value from the '''title''' (and '''abstract''') field, and '''multilang''' fields don't support such functionality. Hence, doing so would cause EPrints to throw errors. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for our '''title''' field (using the data stored in '''ml_title''' field) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish when overriding these functions, as long as their code return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In our example we update the phrases for the English and for the Greek languages ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. So, for the English language we can add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases can be added in file '''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12076</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12076"/>
		<updated>2016-06-07T12:19:35Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Adding the appropriate phrases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. The last statements of our example code show how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value via its corresponding '''multilang''' field ('''ml_title'''). So, each new record now has a '''multilang''' field which it can access via the interface provided by the calculated field of type '''virtualwithvalue''', which is no other than EPrints' basic '''title''' field.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only a single value from the '''title''' (and '''abstract''') field, and '''multilang''' fields don't support such functionality. Hence, doing so would cause EPrints to throw errors. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for our '''title''' field (using the data stored in '''ml_title''' field) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish when overriding these functions, as long as their code return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In our example we update the phrases for the English and for the Greek languages ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. So, for the English language we can add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases can be added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12075</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12075"/>
		<updated>2016-06-07T12:18:51Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Adding the appropriate phrases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. The last statements of our example code show how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value via its corresponding '''multilang''' field ('''ml_title'''). So, each new record now has a '''multilang''' field which it can access via the interface provided by the calculated field of type '''virtualwithvalue''', which is no other than EPrints' basic '''title''' field.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only a single value from the '''title''' (and '''abstract''') field, and '''multilang''' fields don't support such functionality. Hence, doing so would cause EPrints to throw errors. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for our '''title''' field (using the data stored in '''ml_title''' field) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish when overriding these functions, as long as their code return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In our example we update the phrases for the English and for the Greek languages ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12074</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12074"/>
		<updated>2016-06-07T12:18:28Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Adding the appropriate phrases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. The last statements of our example code show how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value via its corresponding '''multilang''' field ('''ml_title'''). So, each new record now has a '''multilang''' field which it can access via the interface provided by the calculated field of type '''virtualwithvalue''', which is no other than EPrints' basic '''title''' field.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only a single value from the '''title''' (and '''abstract''') field, and '''multilang''' fields don't support such functionality. Hence, doing so would cause EPrints to throw errors. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for our '''title''' field (using the data stored in '''ml_title''' field) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish when overriding these functions, as long as their code return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12073</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12073"/>
		<updated>2016-06-07T12:18:08Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Introducing ml_title field in EPrints and replacing title field's type */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. The last statements of our example code show how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value via its corresponding '''multilang''' field ('''ml_title'''). So, each new record now has a '''multilang''' field which it can access via the interface provided by the calculated field of type '''virtualwithvalue''', which is no other than EPrints' basic '''title''' field.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only a single value from the '''title''' (and '''abstract''') field, and '''multilang''' fields don't support such functionality. Hence, doing so would cause EPrints to throw errors. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for our '''title''' field (using the data stored in '''ml_title''' field) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish when overriding these functions, as long as their code return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12072</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12072"/>
		<updated>2016-06-07T12:14:50Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Introducing ml_title field in EPrints and replacing title field's type */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. The last statements of our example code show how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value via its corresponding '''multilang''' field ('''ml_title'''). So, each new record now has a '''multilang''' field which it can access via the interface provided by the calculated field of type '''virtualwithvalue''', which is no other than EPrints' basic '''title''' field.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only a single value from the '''title''' (and '''abstract''') field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12071</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12071"/>
		<updated>2016-06-07T12:14:06Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Introducing ml_title field in EPrints and replacing title field's type */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. The last statements of our example code show how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value via its corresponding '''multilang''' field ('''ml_title'''). So, each new record now has a '''multilang''' field which it can access via the interface provided by the calculated field of type '''virtualwithvalue''', which is no other than EPrints' basic '''title''' field.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only one value from the title (and abstract) field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12070</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12070"/>
		<updated>2016-06-07T12:13:34Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Introducing ml_title field in EPrints and replacing title field's type */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. The last statements of our example code show how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value via its corresponding '''multilang''' field ('''ml_title'''). So, each new record now has a '''multilang''' field which it can access via the interface provided by the calculated field of type '''virtualwithvalue''', which is no other than EPrints basic '''title''' field.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only one value from the title (and abstract) field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12069</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12069"/>
		<updated>2016-06-07T12:11:21Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Introducing ml_title field in EPrints and replacing title field's type */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. The last statements of our example code show how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value via its corresponding multilingual field ('''ml_title'''). So, each new record now has a multilingual field which it accesses via the interface provided by the calculated field of type '''virtualwithvalue'''.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only one value from the title (and abstract) field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12068</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12068"/>
		<updated>2016-06-07T12:10:22Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Introducing ml_title field in EPrints and replacing title field's type */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. The last statements of our example code show how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value in its corresponding multilingual field ('''ml_title'''). So, each new record now has a multilingual field which it accesses via the interface provided by the calculated field of type '''virtualwithvalue'''.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only one value from the title (and abstract) field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12067</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12067"/>
		<updated>2016-06-07T12:08:00Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Introducing ml_title field in EPrints and replacing title field's type */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions -whose names imply their functionality- are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. In the end of our example code, one can see how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value in its corresponding multilingual field ('''ml_title'''). So, each new record now has a multilingual field which it accesses via the interface provided by the calculated field of type '''virtualwithvalue'''.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only one value from the title (and abstract) field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12066</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12066"/>
		<updated>2016-06-07T12:06:49Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Introducing ml_title field in EPrints and replacing title field's type */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements the two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. Their names imply their functionality. In the end of our example code, one can see how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value in its corresponding multilingual field ('''ml_title'''). So, each new record now has a multilingual field which it accesses via the interface provided by the calculated field of type '''virtualwithvalue'''.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only one value from the title (and abstract) field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12065</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12065"/>
		<updated>2016-06-07T11:03:14Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* How to add a custom, multilingual field */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, and ''title''' and '''ml_title''' are used as our example fields. The code snippets are just for demonstration purposes - and proof of concept. If you want to see the final, working implementation, you should look at the source code of the [[MultiLang_Fields_Bazaar_Package]] plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. Their names imply their functionality. In the end of our example code, one can see how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value in its corresponding multilingual field ('''ml_title'''). So, each new record now has a multilingual field which it accesses via the interface provided by the calculated field of type '''virtualwithvalue'''.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only one value from the title (and abstract) field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12064</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12064"/>
		<updated>2016-06-07T11:01:53Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* How to add a custom, multilingual field */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* ''Static files need to be regenerated'' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, where we are using '''ml_title''' as our example field. The code snippets are just for demonstration purposes (and proof of concept). If you want to see the final, working implementation, you should look at the source code of the plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. Their names imply their functionality. In the end of our example code, one can see how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value in its corresponding multilingual field ('''ml_title'''). So, each new record now has a multilingual field which it accesses via the interface provided by the calculated field of type '''virtualwithvalue'''.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only one value from the title (and abstract) field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12063</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12063"/>
		<updated>2016-06-07T11:01:26Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* How to add a custom, multilingual field */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will needs a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* '''Static files need to be regenerated''' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, where we are using '''ml_title''' as our example field. The code snippets are just for demonstration purposes (and proof of concept). If you want to see the final, working implementation, you should look at the source code of the plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. Their names imply their functionality. In the end of our example code, one can see how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value in its corresponding multilingual field ('''ml_title'''). So, each new record now has a multilingual field which it accesses via the interface provided by the calculated field of type '''virtualwithvalue'''.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only one value from the title (and abstract) field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12062</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12062"/>
		<updated>2016-06-07T10:59:34Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Multilang fields and EPrints */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
To address these limitations. this article explains how we can replace a basic field, the '''title''' field as an example, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will contain a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* '''Static files need to be regenerated''' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, where we are using '''ml_title''' as our example field. The code snippets are just for demonstration purposes (and proof of concept). If you want to see the final, working implementation, you should look at the source code of the plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. Their names imply their functionality. In the end of our example code, one can see how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value in its corresponding multilingual field ('''ml_title'''). So, each new record now has a multilingual field which it accesses via the interface provided by the calculated field of type '''virtualwithvalue'''.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only one value from the title (and abstract) field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12061</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12061"/>
		<updated>2016-06-07T10:59:04Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Multilang fields and EPrints */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects a single output.&lt;br /&gt;
&lt;br /&gt;
So this article explains how we can replace a basic field, the '''title''' field, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will contain a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* '''Static files need to be regenerated''' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, where we are using '''ml_title''' as our example field. The code snippets are just for demonstration purposes (and proof of concept). If you want to see the final, working implementation, you should look at the source code of the plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. Their names imply their functionality. In the end of our example code, one can see how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value in its corresponding multilingual field ('''ml_title'''). So, each new record now has a multilingual field which it accesses via the interface provided by the calculated field of type '''virtualwithvalue'''.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only one value from the title (and abstract) field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12060</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12060"/>
		<updated>2016-06-07T10:58:41Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Multilang fields and EPrints */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages containing content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects one output.&lt;br /&gt;
&lt;br /&gt;
So this article explains how we can replace a basic field, the '''title''' field, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will contain a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* '''Static files need to be regenerated''' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, where we are using '''ml_title''' as our example field. The code snippets are just for demonstration purposes (and proof of concept). If you want to see the final, working implementation, you should look at the source code of the plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. Their names imply their functionality. In the end of our example code, one can see how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value in its corresponding multilingual field ('''ml_title'''). So, each new record now has a multilingual field which it accesses via the interface provided by the calculated field of type '''virtualwithvalue'''.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only one value from the title (and abstract) field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12059</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12059"/>
		<updated>2016-06-07T10:57:57Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Adding a new field type (VirtualWithValue) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages which contain content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects one output.&lt;br /&gt;
&lt;br /&gt;
So this article explains how we can replace a basic field, the '''title''' field, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will contain a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* '''Static files need to be regenerated''' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, where we are using '''ml_title''' as our example field. The code snippets are just for demonstration purposes (and proof of concept). If you want to see the final, working implementation, you should look at the source code of the plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' (see [[MetaField]] article for details) is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. Their names imply their functionality. In the end of our example code, one can see how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value in its corresponding multilingual field ('''ml_title'''). So, each new record now has a multilingual field which it accesses via the interface provided by the calculated field of type '''virtualwithvalue'''.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only one value from the title (and abstract) field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12058</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12058"/>
		<updated>2016-06-07T10:56:50Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field -indirectly this means one language support. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with its subsystems.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages which contain content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects one output.&lt;br /&gt;
&lt;br /&gt;
So this article explains how we can replace a basic field, the '''title''' field, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will contain a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* '''Static files need to be regenerated''' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, where we are using '''ml_title''' as our example field. The code snippets are just for demonstration purposes (and proof of concept). If you want to see the final, working implementation, you should look at the source code of the plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. Their names imply their functionality. In the end of our example code, one can see how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value in its corresponding multilingual field ('''ml_title'''). So, each new record now has a multilingual field which it accesses via the interface provided by the calculated field of type '''virtualwithvalue'''.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only one value from the title (and abstract) field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12057</id>
		<title>MultiLang Fields Bazaar Package</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12057"/>
		<updated>2016-06-07T10:55:14Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* How the plugin works */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:EPrints 3 Plugins]]&lt;br /&gt;
&lt;br /&gt;
The MultiLang plugins introduces multiple language support in EPrints fields. The specific plugin replaces the '''title''' and '''abstract''' fields' types with their multilingual versions that calculate their values based on two newly added multilingual fields ('''ml_title''' and '''ml_abstract''' respectively). The wiki-page that explains how one can replace basic EPrints fields with multilang-fields -which basically explains how this plugin was created- is [[Adding multilang fields]]. &lt;br /&gt;
&lt;br /&gt;
== Installation Prerequisites ==&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Install through the EPrints Bazaar.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once this plugin is installed, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to use the plugin ==&lt;br /&gt;
Once the plugin has been installed, the user needs to edit the workflow to contain the multilingual fields' versions instead of the default ones. This procedure is explained in the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Editing the workflow ==&lt;br /&gt;
In order for the plugin to be usable, the default field versions need to be commented out and the new multilingual ones need to be added. So, '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' has to be edited as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports the new '''ml_'''fields. Once the workflow has changed, the repository needs to be reloaded for the changes to take effect:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./epadmin reload reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How the plugin works ==&lt;br /&gt;
Basically, what the plugin does is that it replaces EPrints default '''title''' and '''abstract''' field types with a type that supports storing and retrieving information on multilingual fields. The procedure that we followed in order to achieve this functionality was the following:&lt;br /&gt;
&lt;br /&gt;
* We introduced a new field's type, '''virtualwithvalue''', that would allow our fields to override EPrints fields' default behaviour.&lt;br /&gt;
* We added multilingual versions of the fields that are replaced (namely '''ml_title''' and '''ml_abstract''') to store multilingual content.&lt;br /&gt;
* We introduced our new fields' names, types and functionality to EPrints via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''&lt;br /&gt;
* We added the appropriate phrases in each language's phrase file.&lt;br /&gt;
* We added a custom lookup cgi script that uses the new '''ml_title''' field for the autocompletion feature.&lt;br /&gt;
* We changed EPrints basic and advanced search scripts to search our new multilingual fields instead of the original ones.&lt;br /&gt;
&lt;br /&gt;
A screenshot showing how the two fields look when inserting a new document follows:&lt;br /&gt;
[[File:ruomo_multilang.jpg]]&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12056</id>
		<title>MultiLang Fields Bazaar Package</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12056"/>
		<updated>2016-06-07T10:52:27Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:EPrints 3 Plugins]]&lt;br /&gt;
&lt;br /&gt;
The MultiLang plugins introduces multiple language support in EPrints fields. The specific plugin replaces the '''title''' and '''abstract''' fields' types with their multilingual versions that calculate their values based on two newly added multilingual fields ('''ml_title''' and '''ml_abstract''' respectively). The wiki-page that explains how one can replace basic EPrints fields with multilang-fields -which basically explains how this plugin was created- is [[Adding multilang fields]]. &lt;br /&gt;
&lt;br /&gt;
== Installation Prerequisites ==&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Install through the EPrints Bazaar.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once this plugin is installed, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to use the plugin ==&lt;br /&gt;
Once the plugin has been installed, the user needs to edit the workflow to contain the multilingual fields' versions instead of the default ones. This procedure is explained in the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Editing the workflow ==&lt;br /&gt;
In order for the plugin to be usable, the default field versions need to be commented out and the new multilingual ones need to be added. So, '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' has to be edited as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports the new '''ml_'''fields. Once the workflow has changed, the repository needs to be reloaded for the changes to take effect:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./epadmin reload reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How the plugin works ==&lt;br /&gt;
Basically, what the plugin does is that it replaces EPrints default '''title''' and '''abstract''' fields with two new fields that support multiple languages. The procedure that we followed in order to achieve this functionality was the following:&lt;br /&gt;
&lt;br /&gt;
* We introduced a new field's type, '''virtualwithvalue''', that would allow our fields to override EPrints fields' default behaviour.&lt;br /&gt;
* We added multilingual versions of the fields that are replaced (namely '''ml_title''' and '''ml_abstract''') to store multilingual content.&lt;br /&gt;
* We introduced our new fields' names, types and functionality to EPrints via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''&lt;br /&gt;
* We added the appropriate phrases in each language's phrase file.&lt;br /&gt;
* We added a custom lookup cgi script that uses the new '''ml_title''' field for the autocompletion feature.&lt;br /&gt;
* We changed EPrints basic and advanced search scripts to search our new multilingual fields instead of the original ones.&lt;br /&gt;
&lt;br /&gt;
A screenshot showing how the two fields look when inserting a new document follows:&lt;br /&gt;
[[File:ruomo_multilang.jpg]]&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12055</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12055"/>
		<updated>2016-06-07T10:51:39Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with it.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages which contain content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects one output.&lt;br /&gt;
&lt;br /&gt;
So this article explains how we can replace a basic field, the '''title''' field, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once you follow this article's procedure, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will contain a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* '''Static files need to be regenerated''' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, where we are using '''ml_title''' as our example field. The code snippets are just for demonstration purposes (and proof of concept). If you want to see the final, working implementation, you should look at the source code of the plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. Their names imply their functionality. In the end of our example code, one can see how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value in its corresponding multilingual field ('''ml_title'''). So, each new record now has a multilingual field which it accesses via the interface provided by the calculated field of type '''virtualwithvalue'''.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only one value from the title (and abstract) field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12054</id>
		<title>MultiLang Fields Bazaar Package</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12054"/>
		<updated>2016-06-07T10:50:49Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* Warning to already populated repositories */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:EPrints 3 Plugins]]&lt;br /&gt;
&lt;br /&gt;
The MultiLang plugins introduces multiple language support in EPrints fields. The specific plugin replaces the '''title''' and '''abstract''' fields' types with their multilingual versions that calculate their values based on two newly added multilingual fields ('''ml_title''' and '''ml_abstract''' respectively). The wiki-page that explains how one can replace basic EPrints fields with multilang-fields -which basically explains how this plugin was created- is [[Adding multilang fields]]. &lt;br /&gt;
&lt;br /&gt;
== Installation Prerequisites ==&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Install through the EPrints Bazaar.&lt;br /&gt;
&lt;br /&gt;
== Warning for already populated repositories ==&lt;br /&gt;
Once this plugin is installed, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to use the plugin ==&lt;br /&gt;
Once the plugin has been installed, the user needs to edit the workflow to contain the multilingual fields' versions instead of the default ones. This procedure is explained in [[MultiLang Fields Bazaar Package#How_the_plugin_works]] section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Editing the workflow ==&lt;br /&gt;
In order for the plugin to be usable, the default field versions need to be commented out and the new multilingual ones need to be added. So, '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' has to be edited as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports the new '''ml_'''fields. Once the workflow has changed, the repository needs to be reloaded for the changes to take effect:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./epadmin reload reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How the plugin works ==&lt;br /&gt;
Basically, what the plugin does is that it replaces EPrints default '''title''' and '''abstract''' fields with two new fields that support multiple languages. The procedure that we followed in order to achieve this functionality was the following:&lt;br /&gt;
&lt;br /&gt;
* We introduced a new field's type, '''virtualwithvalue''', that would allow our fields to override EPrints fields' default behaviour.&lt;br /&gt;
* We added multilingual versions of the fields that are replaced (namely '''ml_title''' and '''ml_abstract''') to store multilingual content.&lt;br /&gt;
* We introduced our new fields' names, types and functionality to EPrints via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''&lt;br /&gt;
* We added the appropriate phrases in each language's phrase file.&lt;br /&gt;
* We added a custom lookup cgi script that uses the new '''ml_title''' field for the autocompletion feature.&lt;br /&gt;
* We changed EPrints basic and advanced search scripts to search our new multilingual fields instead of the original ones.&lt;br /&gt;
&lt;br /&gt;
A screenshot showing how the two fields look when inserting a new document follows:&lt;br /&gt;
[[File:ruomo_multilang.jpg]]&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12053</id>
		<title>MultiLang Fields Bazaar Package</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12053"/>
		<updated>2016-06-07T10:50:33Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:EPrints 3 Plugins]]&lt;br /&gt;
&lt;br /&gt;
The MultiLang plugins introduces multiple language support in EPrints fields. The specific plugin replaces the '''title''' and '''abstract''' fields' types with their multilingual versions that calculate their values based on two newly added multilingual fields ('''ml_title''' and '''ml_abstract''' respectively). The wiki-page that explains how one can replace basic EPrints fields with multilang-fields -which basically explains how this plugin was created- is [[Adding multilang fields]]. &lt;br /&gt;
&lt;br /&gt;
== Installation Prerequisites ==&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Install through the EPrints Bazaar.&lt;br /&gt;
&lt;br /&gt;
== Warning to already populated repositories ==&lt;br /&gt;
Once this plugin is installed, '''existing titles and abstracts''' will not be copied into their multilingual counterparts and '''access to them via the API will be lost'''!&lt;br /&gt;
&lt;br /&gt;
== How to use the plugin ==&lt;br /&gt;
Once the plugin has been installed, the user needs to edit the workflow to contain the multilingual fields' versions instead of the default ones. This procedure is explained in [[MultiLang Fields Bazaar Package#How_the_plugin_works]] section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Editing the workflow ==&lt;br /&gt;
In order for the plugin to be usable, the default field versions need to be commented out and the new multilingual ones need to be added. So, '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' has to be edited as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports the new '''ml_'''fields. Once the workflow has changed, the repository needs to be reloaded for the changes to take effect:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./epadmin reload reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How the plugin works ==&lt;br /&gt;
Basically, what the plugin does is that it replaces EPrints default '''title''' and '''abstract''' fields with two new fields that support multiple languages. The procedure that we followed in order to achieve this functionality was the following:&lt;br /&gt;
&lt;br /&gt;
* We introduced a new field's type, '''virtualwithvalue''', that would allow our fields to override EPrints fields' default behaviour.&lt;br /&gt;
* We added multilingual versions of the fields that are replaced (namely '''ml_title''' and '''ml_abstract''') to store multilingual content.&lt;br /&gt;
* We introduced our new fields' names, types and functionality to EPrints via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''&lt;br /&gt;
* We added the appropriate phrases in each language's phrase file.&lt;br /&gt;
* We added a custom lookup cgi script that uses the new '''ml_title''' field for the autocompletion feature.&lt;br /&gt;
* We changed EPrints basic and advanced search scripts to search our new multilingual fields instead of the original ones.&lt;br /&gt;
&lt;br /&gt;
A screenshot showing how the two fields look when inserting a new document follows:&lt;br /&gt;
[[File:ruomo_multilang.jpg]]&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12052</id>
		<title>MultiLang Fields Bazaar Package</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12052"/>
		<updated>2016-06-07T10:24:46Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:EPrints 3 Plugins]]&lt;br /&gt;
&lt;br /&gt;
The MultiLang plugins introduces multiple language support in EPrints fields. The specific plugin replaces the '''title''' and '''abstract''' fields' types with their multilingual versions that calculate their values based on two newly added multilingual fields ('''ml_title''' and '''ml_abstract''' respectively). The wiki-page that explains how one can replace basic EPrints fields with multilang-fields -which basically explains how this plugin was created- is [[Adding multilang fields]]. &lt;br /&gt;
&lt;br /&gt;
== Installation Prerequisites ==&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Install through the EPrints Bazaar.&lt;br /&gt;
&lt;br /&gt;
== How to use the plugin ==&lt;br /&gt;
Once the plugin has been installed, the user needs to edit the workflow to contain the multilingual fields' versions instead of the default ones. This procedure is explained in [[MultiLang Fields Bazaar Package#How_the_plugin_works]] section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Editing the workflow ==&lt;br /&gt;
In order for the plugin to be usable, the default field versions need to be commented out and the new multilingual ones need to be added. So, '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' has to be edited as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports the new '''ml_'''fields. Once the workflow has changed, the repository needs to be reloaded for the changes to take effect:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./epadmin reload reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How the plugin works ==&lt;br /&gt;
Basically, what the plugin does is that it replaces EPrints default '''title''' and '''abstract''' fields with two new fields that support multiple languages. The procedure that we followed in order to achieve this functionality was the following:&lt;br /&gt;
&lt;br /&gt;
* We introduced a new field's type, '''virtualwithvalue''', that would allow our fields to override EPrints fields' default behaviour.&lt;br /&gt;
* We added multilingual versions of the fields that are replaced (namely '''ml_title''' and '''ml_abstract''') to store multilingual content.&lt;br /&gt;
* We introduced our new fields' names, types and functionality to EPrints via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''&lt;br /&gt;
* We added the appropriate phrases in each language's phrase file.&lt;br /&gt;
* We added a custom lookup cgi script that uses the new '''ml_title''' field for the autocompletion feature.&lt;br /&gt;
* We changed EPrints basic and advanced search scripts to search our new multilingual fields instead of the original ones.&lt;br /&gt;
&lt;br /&gt;
A screenshot showing how the two fields look when inserting a new document follows:&lt;br /&gt;
[[File:ruomo_multilang.jpg]]&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12051</id>
		<title>MultiLang Fields Bazaar Package</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12051"/>
		<updated>2016-06-07T10:23:48Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* How the plugin works */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:EPrints 3 Plugins]]&lt;br /&gt;
&lt;br /&gt;
The MultiLang plugins introduces multiple language support in EPrints fields. The specific plugin replaces the '''title''' and '''abstract''' fields' types with their multilingual versions that calculate their values based on two newly added multilingual fields ('''ml_title''' and '''ml_abstract''' respectively). The wiki-page that explains how one can replace basic EPrints fields with multilang-fields -which basically explains how this plugin was created- is [[Adding multilang fields]]. &lt;br /&gt;
&lt;br /&gt;
== Installation Prerequisites ==&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Install through the EPrints Bazaar.&lt;br /&gt;
&lt;br /&gt;
== How to use the plugin ==&lt;br /&gt;
Once the plugin has been installed, the user needs to edit the workflow to contain the multilingual fields' versions instead of the default ones. This procedure is explained in [[MultiLang Fields Bazaar Package#How_the_plugin_works]] section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Editing the workflow ==&lt;br /&gt;
In order for the plugin to be usable, the default field versions need to be commented out and the new multilingual ones need to be added. So, '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' has to be edited as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports the new '''ml_'''fields. Once the workflow has changed, the repository needs to be reloaded for the changes to take effect:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./epadmin reload reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How the plugin works ==&lt;br /&gt;
Basically, what the plugin does is that it replaces EPrints default '''title''' and '''abstract''' fields with two new fields that support multiple languages. The procedure that we followed in order to achieve this functionality was the following:&lt;br /&gt;
&lt;br /&gt;
* We introduced a new field's type, '''virtualwithvalue''', that would allow our fields to override EPrints fields' default behaviour.&lt;br /&gt;
* We added multilingual versions of the fields that are replaced (namely '''ml_title''' and '''ml_abstract''') to store multilingual content.&lt;br /&gt;
* We introduced our new fields' names, types and functionality to EPrints via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''&lt;br /&gt;
* We added the appropriate phrases in each language's phrase file.&lt;br /&gt;
* We added a custom lookup cgi script that uses the new '''ml_title''' field for the autocompletion feature.&lt;br /&gt;
* We changed EPrints basic and advanced search scripts to search our new multilingual fields instead of the original ones.&lt;br /&gt;
&lt;br /&gt;
A screenshot showing how the two fields look when inserting a new document follows:&lt;br /&gt;
[[File:ruomo_multilang.jpg]]&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12050</id>
		<title>MultiLang Fields Bazaar Package</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=MultiLang_Fields_Bazaar_Package&amp;diff=12050"/>
		<updated>2016-06-07T10:20:28Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:EPrints 3 Plugins]]&lt;br /&gt;
&lt;br /&gt;
The MultiLang plugins introduces multiple language support in EPrints fields. The specific plugin replaces the '''title''' and '''abstract''' fields' types with their multilingual versions that calculate their values based on two newly added multilingual fields ('''ml_title''' and '''ml_abstract''' respectively). The wiki-page that explains how one can replace basic EPrints fields with multilang-fields -which basically explains how this plugin was created- is [[Adding multilang fields]]. &lt;br /&gt;
&lt;br /&gt;
== Installation Prerequisites ==&lt;br /&gt;
None.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Install through the EPrints Bazaar.&lt;br /&gt;
&lt;br /&gt;
== How to use the plugin ==&lt;br /&gt;
Once the plugin has been installed, the user needs to edit the workflow to contain the multilingual fields' versions instead of the default ones. This procedure is explained in [[MultiLang Fields Bazaar Package#How_the_plugin_works]] section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Editing the workflow ==&lt;br /&gt;
In order for the plugin to be usable, the default field versions need to be commented out and the new multilingual ones need to be added. So, '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' has to be edited as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports the new '''ml_'''fields. Once the workflow has changed, the repository needs to be reloaded for the changes to take effect:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
./epadmin reload reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How the plugin works ==&lt;br /&gt;
Basically, what the plugin does is that it replaces EPrints default '''title''' and '''abstract''' fields with two new fields that support multiple languages. The procedure that we followed in order to achieve this functionality was the following:&lt;br /&gt;
&lt;br /&gt;
* We introduced a new field's type, '''virtualwithvalue''', that would allow our fields to override EPrints fields' default behaviour.&lt;br /&gt;
* We introduced our new fields' names, types and functionality to EPrints via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''&lt;br /&gt;
* We added the appropriate phrases in each language's phrase file.&lt;br /&gt;
* We added a custom lookup cgi script that uses the new '''ml_title''' field for the autocompletion feature.&lt;br /&gt;
* We changed EPrints basic and advanced search scripts to search our new multilingual fields instead of the original ones.&lt;br /&gt;
&lt;br /&gt;
A screenshot showing how the two fields look when inserting a new document follows:&lt;br /&gt;
[[File:ruomo_multilang.jpg]]&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12049</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12049"/>
		<updated>2016-06-07T10:16:55Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with it.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages which contain content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects one output.&lt;br /&gt;
&lt;br /&gt;
So this article explains how we can replace a basic field, the '''title''' field, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will contain a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* '''Static files need to be regenerated''' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, where we are using '''ml_title''' as our example field. The code snippets are just for demonstration purposes (and proof of concept). If you want to see the final, working implementation, you should look at the source code of the plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. Their names imply their functionality. In the end of our example code, one can see how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value in its corresponding multilingual field ('''ml_title'''). So, each new record now has a multilingual field which it accesses via the interface provided by the calculated field of type '''virtualwithvalue'''.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only one value from the title (and abstract) field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;br /&gt;
&lt;br /&gt;
== Regenerating static files and abstracts ==&lt;br /&gt;
If our repository already contained records, we need to recreate static content such as static pages and abstracts. Hence, as eprints user we should run:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/generate_abstracts reponame&lt;br /&gt;
$ ./bin/generate_static reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12048</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12048"/>
		<updated>2016-06-07T10:14:34Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: /* How to add a custom, multilingual field */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with it.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages which contain content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects one output.&lt;br /&gt;
&lt;br /&gt;
So this article explains how we can replace a basic field, the '''title''' field, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will contain a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
* '''Static files need to be regenerated''' if our repository already contains data.&lt;br /&gt;
The following sections explain each step in detail, where we are using '''ml_title''' as our example field. The code snippets are just for demonstration purposes (and proof of concept). If you want to see the final, working implementation, you should look at the source code of the plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. Their names imply their functionality. In the end of our example code, one can see how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value in its corresponding multilingual field ('''ml_title'''). So, each new record now has a multilingual field which it accesses via the interface provided by the calculated field of type '''virtualwithvalue'''.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only one value from the title (and abstract) field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12047</id>
		<title>Adding multilang fields</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Adding_multilang_fields&amp;diff=12047"/>
		<updated>2016-06-07T10:13:18Z</updated>

		<summary type="html">&lt;p&gt;Mamalos@eng.auth.gr: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;EPrints' builtin fields are not multilingual, in the sense that there is only one version of each field. This page explains how to add multilingual versions of existing fields in EPrints and how they can be integrated with it.&lt;br /&gt;
&lt;br /&gt;
== Multilang fields and EPrints ==&lt;br /&gt;
EPrints supports the '''multilang''' field type (see [[Multilang]] for more details) which allows a user to insert different content for different languages. There are a few limitations with '''multilang''' fields though:&lt;br /&gt;
&lt;br /&gt;
* When its value is printed it is shown in all languages which contain content.&lt;br /&gt;
* If a basic EPrints field's type is replaced to become '''multilang''' (like '''title''' and '''abstract'''), EPrints functionality breaks because it expects one output.&lt;br /&gt;
&lt;br /&gt;
So this article explains how we can replace a basic field, the '''title''' field, with a multilingual one.&lt;br /&gt;
&lt;br /&gt;
== How to add a custom, multilingual field ==&lt;br /&gt;
Replacing an EPrints basic field, like the '''title''' field, involves a few steps. First, a new field needs to be created that will be able to store information for different languages; this field will be of type '''multilang'''. Next, the basic field's type needs to be replaced with one that is able to use our newly created field as its storage place. This field type will use a function wrapper for storing and retrieving information from the '''multilang''' field, hence the '''title''' field will become a calculated field.&lt;br /&gt;
&lt;br /&gt;
So, in order to add multilingual support for the '''title''' field, the following actions need to take place:&lt;br /&gt;
&lt;br /&gt;
* A ''new field type needs to be created'' that will help our '''title''' field to implement some of EPrints logic. Our field type is called '''virtualwithvalue'''.&lt;br /&gt;
* A ''new '''multilang''' field needs to be created'' that will store our multilingual information. We will call this field '''ml_title'''.&lt;br /&gt;
* '''''ml_title''' field and '''title''' field's functionality need to be introduced to the EPrints system'' via a configuration file located in '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/'''.&lt;br /&gt;
* ''EPrints' database needs to be updated'' to include the new field. &lt;br /&gt;
* ''The appropriate phrases need to be added'' for the '''ml_title''' field on each supported language.&lt;br /&gt;
* ''The '''title''' field needs to be replaced'' with '''ml_title''' field in the workflow.&lt;br /&gt;
* '''''ml_title''' field in the workflow will contain a custom lookup script''.&lt;br /&gt;
* ''The '''title''' field needs to be replaced with the '''ml_title''' field in the simple and advanced search scripts''.&lt;br /&gt;
* The ''repository needs to be reloaded''.&lt;br /&gt;
The following sections explain each step in detail, where we are using '''ml_title''' as our example field. The code snippets are just for demonstration purposes (and proof of concept). If you want to see the final, working implementation, you should look at the source code of the plugin.&lt;br /&gt;
&lt;br /&gt;
== Adding a new field type (VirtualWithValue)==&lt;br /&gt;
In order to create a multiple-language field we have to create an appropriate field type. EPrints' '''MetaField''' is a perfect candidate for this, and we need to extend it and override its '''get_value''' and '''set_value''' functions for the field to work properly with the rest of EPrints API, as well as its '''get_property_defaults''' function to sort out warnings for default values. The following code could be a rough implementation of such a field:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;package EPrints::MetaField::Virtualwithvalue;&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
use warnings;&lt;br /&gt;
&lt;br /&gt;
use EPrints::MetaField;&lt;br /&gt;
&lt;br /&gt;
our @ISA = qw( EPrints::MetaField );&lt;br /&gt;
&lt;br /&gt;
use strict;&lt;br /&gt;
&lt;br /&gt;
sub get_property_defaults&lt;br /&gt;
{&lt;br /&gt;
    my ( $self ) = @_;&lt;br /&gt;
    my %defaults = $self-&amp;gt;SUPER::get_property_defaults;&lt;br /&gt;
    $defaults{get_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
    $defaults{set_value} = $EPrints::MetaField::UNDEF;&lt;br /&gt;
&lt;br /&gt;
    return %defaults;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub get_value&lt;br /&gt;
{&lt;br /&gt;
    my( $self, $object ) = @_;&lt;br /&gt;
    if ( defined $self-&amp;gt;get_property(&amp;quot;get_value&amp;quot;) )&lt;br /&gt;
    {&lt;br /&gt;
        return $self-&amp;gt;call_property( &amp;quot;get_value&amp;quot;, $object);&lt;br /&gt;
    }&lt;br /&gt;
    return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub set_value&lt;br /&gt;
{&lt;br /&gt;
     my( $self, $object, $value ) = @_;&lt;br /&gt;
     if ( defined $self-&amp;gt;get_property(&amp;quot;set_value&amp;quot;) )&lt;br /&gt;
     {&lt;br /&gt;
         return $self-&amp;gt;call_property( &amp;quot;set_value&amp;quot;, $object, $value);&lt;br /&gt;
     }&lt;br /&gt;
     return undef;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could save this file in '''~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm'''.&lt;br /&gt;
&lt;br /&gt;
== Introducing ml_title field in EPrints and replacing title field's type==&lt;br /&gt;
To inform EPrints about our new field (that will be of type '''virtualwithvalue'''), we should create a configuration file, eg: '''~eprints/archives/&amp;lt;reponame&amp;gt;/cfg/cfg.d/zz_multilang_field.pl''' with content like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='perl'&amp;gt;&lt;br /&gt;
#define local fields&lt;br /&gt;
my $local_fields = [&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'ml_title',&lt;br /&gt;
    type =&amp;gt; 'multilang',&lt;br /&gt;
    multiple =&amp;gt; 1,&lt;br /&gt;
    fields =&amp;gt; [ { sub_name =&amp;gt; &amp;quot;text&amp;quot;, type =&amp;gt; &amp;quot;longtext&amp;quot;, input_rows =&amp;gt; 3, make_single_value_orderkey =&amp;gt; 'EPrints::Extras::english_title_orderkey' } ],&lt;br /&gt;
    input_add_boxes =&amp;gt; 1,&lt;br /&gt;
},&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    name =&amp;gt; 'title',&lt;br /&gt;
    type =&amp;gt; 'virtualwithvalue',&lt;br /&gt;
    virtual =&amp;gt; 1,&lt;br /&gt;
&lt;br /&gt;
    get_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint) = @_;&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            my $lang = $eprint-&amp;gt;repository-&amp;gt;get_langid;&lt;br /&gt;
            my $lang_set = 0;&lt;br /&gt;
            my $vals = $eprint-&amp;gt;get_value('ml_title');&lt;br /&gt;
            my $title = '';&lt;br /&gt;
            if (!$lang)&lt;br /&gt;
            {&lt;br /&gt;
                $lang_set = 1;&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                # set the default lang's text as title&lt;br /&gt;
                foreach my $v1 (@{$vals})&lt;br /&gt;
                {&lt;br /&gt;
                    if ($v1-&amp;gt;{lang} eq $lang)&lt;br /&gt;
                    {&lt;br /&gt;
                        $title = $v1-&amp;gt;{text};&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            # if the language is not set or I can't find an abstract in the &lt;br /&gt;
            # user's language, get the first object's text as abstract&lt;br /&gt;
            if ($lang_set or $title eq '')&lt;br /&gt;
            {&lt;br /&gt;
                $title = $vals-&amp;gt;[0]-&amp;gt;{text};&lt;br /&gt;
            }&lt;br /&gt;
            return $title;&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
        return undef;&lt;br /&gt;
    },&lt;br /&gt;
&lt;br /&gt;
    set_value =&amp;gt; sub&lt;br /&gt;
    {&lt;br /&gt;
        my ($eprint, $value) = @_;&lt;br /&gt;
        my $lang = 'en';&lt;br /&gt;
        #only use this on imports, NOT if the value is already set&lt;br /&gt;
        if ($eprint-&amp;gt;is_set('ml_title'))&lt;br /&gt;
        {&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        if ($value)&lt;br /&gt;
        {&lt;br /&gt;
            $eprint-&amp;gt;set_value('ml_title', [{lang=&amp;gt;$lang, text=&amp;gt;$value}]);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
},&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#create lookup hash of local field names&lt;br /&gt;
my $local_fieldnames = {};&lt;br /&gt;
&lt;br /&gt;
foreach my $f (@{$local_fields})&lt;br /&gt;
{&lt;br /&gt;
    $local_fieldnames-&amp;gt;{$f-&amp;gt;{name}} = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#merge in existing field configurations&lt;br /&gt;
foreach my $f (@{$c-&amp;gt;{fields}-&amp;gt;{eprint}})&lt;br /&gt;
{&lt;br /&gt;
    if (!$local_fieldnames-&amp;gt;{$f-&amp;gt;{name}})&lt;br /&gt;
    {&lt;br /&gt;
     push @{$local_fields}, $f;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#overwrite original array of configured fields&lt;br /&gt;
$c-&amp;gt;{fields}-&amp;gt;{eprint} = $local_fields;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where we can see that our new '''ml_title''' field is of type '''multilang''' and the '''title''' field's type has become '''virtualwithvalue'''. Moreover, the '''title''' field now implements two aforementioned functions: '''get_value''' and '''set_value'''. Both these functions are used by EPrints API, and their existence, as well as their return values, are critical for EPrints to work properly. Their names imply their functionality. In the end of our example code, one can see how a custom field can be added in the list of EPrints fields.&lt;br /&gt;
&lt;br /&gt;
What has happened in effect is that the '''title''' field has become a calculated field that gets or sets its value in its corresponding multilingual field ('''ml_title'''). So, each new record now has a multilingual field which it accesses via the interface provided by the calculated field of type '''virtualwithvalue'''.&lt;br /&gt;
&lt;br /&gt;
The reason we didn't set the '''title''' field to be of type '''multilang''' in the first place is that many EPrints builtin functions expect only one value from the title (and abstract) field, and '''multilang''' fields don't support such functionality, which causes EPrints to err. By using and extending calculated fields (like '''MetaFields'''), we can calculate and produce always a single output for the '''multilang''' field (based on some condition) via its '''get_value''' function; its '''set_value''' function is used for populating our '''ml_title''' field's values. Our sample code prints output based on the user's language settings, but the programmer can do whatever they wish in these functions, as long as they return values that comply with EPrints' API.&lt;br /&gt;
&lt;br /&gt;
== Adding the appropriate phrases ==&lt;br /&gt;
EPrints phrases are not aware of our new field ('''ml_title'''), so we need to update them. In Our example we update the phrases for the English and for the Greek language ('''en''' and '''el''' respectively). We chose to add new files instead of changing the default ones so as to help EPrints upgrades. For the English language we add the file '''~eprints/archives/reponame/cfg/lang/en/phrases/local.xml''' that contains the following information:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Title&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Text&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Language&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;A brief history of time&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Life: an unauthorised biography&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Mathematics for engineers and scientists. 5th edition&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Example: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Ecosystems of the world. Vol. 26. Estuaries of the world&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Greek phrases are added in file ''~eprints/archives/reponame/cfg/lang/el/phrases/local.xml''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title&amp;quot;&amp;gt;Τίτλος&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_text&amp;quot;&amp;gt;Κείμενο&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_help&amp;quot;&amp;gt;Το help τεξτ&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldname_ml_title_lang&amp;quot;&amp;gt;Γλώσσα&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;epp:phrase id=&amp;quot;eprint_fieldhelp_ml_title&amp;quot;&amp;gt;Ο τίτλος του τεκμηρίου. Ο τίτλος δεν πρέπει να τελειώνει με τελεία, αλλά μπορεί να τελειώνει με ερωτηματικό. Δεν υπάρχει τρόπος να γράψετε με πλάγια γράμματα, παρακαλώ χρησιμοποιήστε απλό κείμενο. Εάν έχετε έναν υπότιτλο, θα πρέπει να προηγείται η άνω και κάτω τελεία του υπότιτλου [:]. Χρησιμοποιήστε κεφαλαία γράμματα μόνο στην πρώτη λέξη και στα κύρια ονόματα.&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μια σύντομη ιστορία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Καβάφης: η βιογραφία&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Μαθηματικά για μηχανικούς και επιστήμονες. 5η έκδοση&amp;lt;/span&amp;gt;&lt;br /&gt;
    &amp;lt;br/&amp;gt;Παράδειγμα: &amp;lt;span class=&amp;quot;ep_form_example&amp;quot;&amp;gt;Οικοσυστήματα του πλανήτη. Τόμ. 26. Εκβολές του πλανήτη.&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/epp:phrase&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Replacing the title field with ml_title field in the workflow ==&lt;br /&gt;
In order to use our new '''ml_title''' field in the workflow, we need to replace the existing one ('''title'''). So, the '''title''' needs to be commented out and the new multilingual one need is added. This means that '''~eprints/archives/reponame/cfg/workflows/eprint/default.xml''' is edited as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;!--    &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=title&amp;quot; /&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_title&amp;quot; required=&amp;quot;yes&amp;quot; input_lookup_url=&amp;quot;{$config{rel_cgipath}}/users/lookup/ml_title_duplicates&amp;quot; input_lookup_params=&amp;quot;id={eprintid}&amp;amp;amp;dataset=eprint&amp;amp;amp;field=ml_title&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
    &amp;lt;component&amp;gt;&amp;lt;field ref=&amp;quot;ml_abstract&amp;quot;/&amp;gt;&amp;lt;/component&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As can be seen, the default lookup script is replaced by the plugin's lookup script ('''ml_title_duplicates''') which supports our new '''ml_title''' field.&lt;br /&gt;
&lt;br /&gt;
== Updating EPrints database to include the ml_title field ==&lt;br /&gt;
EPrints database is updated when the user eprints executes (from his home directory):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin update reponame&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Adding a custom lookup script for ml_title autocompletion ==&lt;br /&gt;
We copy the default lookup script to a new one ('''~eprints/cgi/users/lookup/ml_title_duplicates in our example'''):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cp ~eprints/cgi/users/lookup/title_duplicates ~eprints/cgi/users/lookup/ml_title_duplicates&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
and edit the SQL statement to contain '''ml_title''' instead of '''title''' (line 70 in EPrints 3.3.14):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
my $sql = &amp;quot;SELECT ep.eprintid, ml_title_text FROM eprint AS ep JOIN eprint_ml_title_text AS ml ON ep.eprintid = ml.eprintid WHERE &amp;quot;;&lt;br /&gt;
if ($dataset_name eq &amp;quot;eprint&amp;quot;) {&lt;br /&gt;
    $sql .= &amp;quot; $Q_eprint_status=&amp;quot; .  $db-&amp;gt;quote_value( &amp;quot;archive&amp;quot; ) . &amp;quot; AND &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
$sql .= &amp;quot;ml.ml_title_text IS NOT NULL&amp;quot; .&lt;br /&gt;
    &amp;quot; AND ml.ml_title_text &amp;quot; .&lt;br /&gt;
    $db-&amp;gt;sql_LIKE() .&lt;br /&gt;
    $db-&amp;gt;quote_value( EPrints::Database::prep_like_value( $q ) . '%' );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding search support for the ml_title field ==&lt;br /&gt;
We should allow our search scripts to be able to search into '''ml_title''' instead of  '''title''', since '''title''' is now a calculated field and contains no information in EPrints database. To do so, we add two configuration files that add support for each search respectively. We chose not to change EPrints default search configuration files in order to to affect future EPrints upgrades. So, for the simple search we add the file '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_simple.pl''' with the content:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;$c-&amp;gt;{search}-&amp;gt;{simple} = &lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        {&lt;br /&gt;
            id =&amp;gt; &amp;quot;q&amp;quot;,&lt;br /&gt;
            meta_fields =&amp;gt; [&lt;br /&gt;
                &amp;quot;documents&amp;quot;,&lt;br /&gt;
                &amp;quot;ml_title&amp;quot;,&lt;br /&gt;
                &amp;quot;abstract&amp;quot;,&lt;br /&gt;
                &amp;quot;creators_name&amp;quot;,&lt;br /&gt;
                &amp;quot;date&amp;quot; &lt;br /&gt;
            ]&lt;br /&gt;
        },&lt;br /&gt;
    ],&lt;br /&gt;
#    preamble_phrase =&amp;gt; &amp;quot;cgi/search:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/search:simple_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;      =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;     =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;       =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;      =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And for the advanced search we add the file: '''~eprints/archives/reponame/cfg/cfg.d/eprint_search_advanced_local.pl''' that reads:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$c-&amp;gt;{search}-&amp;gt;{advanced} =&lt;br /&gt;
{&lt;br /&gt;
    search_fields =&amp;gt; [&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ml_title&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;creators_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;abstract&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;date&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;keywords&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;subjects&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;type&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;department&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;editors_name&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;ispublished&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;refereed&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;publication&amp;quot; ] },&lt;br /&gt;
        { meta_fields =&amp;gt; [ &amp;quot;documents.format&amp;quot; ] },&lt;br /&gt;
    ],&lt;br /&gt;
    preamble_phrase =&amp;gt; &amp;quot;cgi/advsearch:preamble&amp;quot;,&lt;br /&gt;
    title_phrase =&amp;gt; &amp;quot;cgi/advsearch:adv_search&amp;quot;,&lt;br /&gt;
    citation =&amp;gt; &amp;quot;result&amp;quot;,&lt;br /&gt;
    page_size =&amp;gt; 20,&lt;br /&gt;
    order_methods =&amp;gt; {&lt;br /&gt;
        &amp;quot;byyear&amp;quot;     =&amp;gt; &amp;quot;-date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byyearoldest&amp;quot;   =&amp;gt; &amp;quot;date/creators_name/title&amp;quot;,&lt;br /&gt;
        &amp;quot;byname&amp;quot;     =&amp;gt; &amp;quot;creators_name/-date/title&amp;quot;,&lt;br /&gt;
        &amp;quot;bytitle&amp;quot;    =&amp;gt; &amp;quot;title/creators_name/-date&amp;quot; &lt;br /&gt;
    },&lt;br /&gt;
    default_order =&amp;gt; &amp;quot;byyear&amp;quot;,&lt;br /&gt;
    show_zero_results =&amp;gt; 1,&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reloading our repository ==&lt;br /&gt;
In order for our changes to take effect, we should reload our repository by running:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ./bin/epadmin reload reponame&amp;lt;/source&amp;gt;&lt;br /&gt;
within eprints user's home directory as user eprints.&lt;/div&gt;</summary>
		<author><name>Mamalos@eng.auth.gr</name></author>
		
	</entry>
</feed>