Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Building VIVO and Vitro language repositories from source (for developers)

  • Clone the VIVO-languages and Vitro-languages repositories to your local machine.
  • Ensure the <version> in the pom.xml files for VIVO and Vitro-languages matches the <version> of VIVO you are building against.  You may need to change the version in multiple places in the files.
  • Go into each language folder (VIVO-language and Vitro-language) and install them with Maven using mvn install
  • Build VIVO from the VIVO project folder using mvn install -o -s installer/my-settings.xml (Note the -o flag, this forces Maven to use the language projects from your local repository instead of downloading from a remote repository)  
  • Edit the vivo_home_dir/config/runtime.properties file in your VIVO home directory:
    • uncomment/add RDFService.languageFilter = true
    • uncomment/add languages.selectableLocales = en_US, de_DE
  • Restart the tomcat
  • You should now be able to select your installed language (in this case German) in the header of your VIVO site

...

You can get the US English (en_US) home/src/main/resources/rdf/i18n/en_US) files from the VIVO -language and Vitro -language among the vivo-project repositories (https://github.com/vivo-project), to use as a template for your own files. 

The process simply consists of duplicating each file having the extension en_US inside  VIVO/Vitro -language  repositories and renaming the copy using the locale of the new language. The new files will reside in a directory named after the new locale.

For example, when initializing the languages files for Estonian (et_EE),  copying the file vivo_all_en_US.properties will help creating vivo_all_et_EE.properties. The new file will reside in vivo-languages/et_EE/webapp/src/main/webapp/i18n

In the process of initializing the files for a new language. You will encounter the following types of file:

Text strings (.properties)

These files contain about 1500 words and phrases that appear in the VIVO/Vitro web pages.

These words and phrases have been removed from the page templates, so no programming knowledge is required to translate them.

They appear at different level in the application :

  • in Vitro-languages/webapp/src/main/webapp/i18n
  • in VIVO-languages/webapp/src/main/webapp/i18n
  • in each theme's i18n directory. For instance : 
    • VIVO-languages/en_US/webapp/src/main/webapp/themes/tenderfoot/i18n and
    • VIVO-languages/en_US/webapp/src/main/webapp/themes/wilma/i18n

making a directory inside  VIVO and Vitro directories home/src/main/resources/rdf/i18n/, for instance et_EE (for Estonian), and copying there the complete file hierarchy from home/src/main/resources/rdf/i18n/en_US. In all copied ttl, n3, nt files, the @en-US language tags should be replaced with @ee-EE, and associated labels should be translated from English to Estonian.

In the process of initializing the files for a new language. You will encounter the following types of file:


User interface labels 

These files contain about 1500 words and phrases that appear in the VIVO/Vitro web pages.

These words and phrases have been removed from the page templates, so no programming knowledge is required to translate them.

They appear at different level in the application (the <locale> might be for instance en_US) :

  • in Vitro - home/src/main/resources/rdf/i18n/<locale>/interface-i18n/firsttime/vitro_UiLabel.ttl
  • in VIVO - home/src/main/resources/rdf/i18n/<locale>/interface-i18n/firsttime/vivo_UiLabel.ttl
    • There are also files for themes: 
      • home/src/main/resources/rdf/i18n/<locale>/interface-i18n/firsttime/vivo_UiLabel_wilma.ttl and
      • home/src/main/resources/rdf/i18n/<locale>/interface-i18n/firsttime/vivo_UiLabel_tenderfoot.ttl

The structure of those files is defined in the Vitro UI label vocabulary (in Vitro - home/src/main/resources/rdf/tbox/firsttime/UILabelsVocabulary.ttl).

The application will look for an entry starting with the activated theme (like tenderfoot or wilma), then VIVO and lastly Vitro.

Freemarker Templates (.ftl)

Almost all of the text in the Freemarker templates is supplied by the text strings in the properties files. However, some Freemarker templates are essentially all text, and it seemed simpler to create a translation of the entire template. These include the help and about pages, the Terms of Use page, and the emails that are sent to new VIVO users.

They are located in:

  • Vitro-languages/<locale>/webapp/src/main/webapp/templates/freemarker
  • VIVO-languages/<locale>/webapp/src/main/webapp/templates/freemarker/body
  • VIVO-languages/<locale>/webapp/src/main/webapp/templates/freemarker/visualization/capabilitymap
  • VIVO-languages/<locale>/webapp/src/main/webapp/templates/freemarker/visualization/mapOfScience

...

Code Block
titleExample file names
Vitro-languages/et_EE/webapp/src/main/webapp/templates/freemarker/search-help_et_EE.ftl
Vitro-languages/et_EE/webapp/src/main/webapp/templates/freemarker/termsOfUse_et_EE.ftl
Vitro-languages/et_EE/webapp/src/main/webapp/templates/freemarker/userAccounts-acctCreatedEmail_et_EE.ftl
Vitro-languages/et_EE/webapp/src/main/webapp/templates/freemarker/userAccounts-acctCreatedExternalOnlyEmail_et_EE.ftl
Vitro-languages/et_EE/webapp/src/main/webapp/templates/freemarker/userAccounts-confirmEmailChangedEmail_et_EE.ftl
Vitro-languages/et_EE/webapp/src/main/webapp/templates/freemarker/userAccounts-firstTimeExternalEmail_et_EE.ftl
Vitro-languages/et_EE/webapp/src/main/webapp/templates/freemarker/userAccounts-passwordCreatedEmail_et_EE.ftl
Vitro-languages/et_EE/webapp/src/main/webapp/templates/freemarker/userAccounts-passwordResetCompleteEmail_et_EE.ftl
Vitro-languages/et_EE/webapp/src/main/webapp/templates/freemarker/userAccounts-passwordResetPendingEmail_et_EE.ftl
VIVO-languages/et_EE/webapp/src/main/webapp/templates/freemarker/body/aboutMapOfScience_et_EE.ftl
VIVO-languages/et_EE/webapp/src/main/webapp/templates/freemarker/body/aboutQrCodes_et_EE.ftl
VIVO-languages/et_EE/webapp/src/main/webapp/templates/freemarker/visualization/mapOfScience/mapOfScienceTooltips_et_EE.ftl
Code Block
titleTerms of Use (Estonian)
<section id="terms" role="region">
    <h2>kasutustingimused</h2> 
    
    <h3>Hoiatused</h3> 

    <p>
        See ${termsOfUse.siteName} veebisait sisaldab materjali; teksti informatsiooni 
        avaldamine tsitaadid, viited ja pildid ikka teie poolt ${termsOfUse.siteHost} 
        ja erinevate kolmandatele isikutele, nii üksikisikute ja organisatsioonide, 
        äri-ja muidu. Sel määral copyrightable Siin esitatud infot VIVO veebilehel ja 
        kättesaadavaks Resource Description Framework (RDF) andmed alates VIVO at 
        ${termsOfUse.siteHost} on mõeldud avalikuks kasutamiseks ja vaba levitamise 
        tingimuste kohaselt 
        <a href="http://creativecommons.org/licenses/by/3.0/" 
                target="_blank" title="creative commons">
            Creative Commons CC-BY 3.0
        </a> 
        litsentsi, mis võimaldab teil kopeerida, levitada, kuvada ja muuta derivaadid 
        seda teavet teile anda laenu ${termsOfUse.siteHost}.  
    </p>
</section>

RDF data (.n3, .nt)

Data in the RDF models include labels for the properties and classes, labels for property groups and class groups, labels for menu pages and more. Here is the list of directories where one will have to create required rdf files:

...

Of course, the selected locale (UI language) will be taken into account. 

NOTE: VIVO/Vitro 1.13 was based on property files located in VIVO-languages and Vitro-languages repositories. Although, those repositories have been archived, and property files have been replaced with ttl files and moved to VIVO and Vitro home directory in VIVO/Vitro 1.14.0 release, due to back compatibility VIVO/Vitro 1.14 also supports using property files. It means, instead of previously listed files, customers can add vivo_all_<locale>.property and vitro_all_<locale>.property into the webapp/src/main/webapp/i18n directory. 

RDF data (.n3, .nt)

Data in the RDF models include labels for the properties and classes, labels for property groups and class groups, labels for menu pages and more. Here is the list of directories where one will have to create required rdf files:

  • [VIVO]/home/src/main/resources/rdf/i18n/<locale>/applicationMetadata/firsttime
  • [VIVO]/home/src/main/resources/rdf/i18n/<locale>/display/firsttime
  • [VIVO]/home/src/main/resources/rdf/i18n/<locale>/tbox/firsttime
  • [Vitro]/home/src/main/resources/rdf/i18n/<locale>/display/firsttime
  • [Vitro]/home/src/main/resources/rdf/i18n/<locale>/tbox/firsttime

In each case, the delivered file in English has a corresponding file with the same name but in a different directory structure (locale tag is different).  for instance:

Code Block
titleFile names (Estonian)
[VIVO]/home/src/main/resources/rdf/i18n/et_EE/applicationMetadata/firsttime/classgroups_labels.n3

In each file, labels specify text to be used by VIVO.  Each label should be translated and affixed with the appropriate locale tag.  See below:

Code Block
titleSome classgroups_labels (Estonian)
<http://vivoweb.org/ontology#vitroClassGrouppeople> 
    <http://www.w3.org/2000/01/rdf-schema#label> "inimesed"@et-EE .
<http://vivoweb.org/ontology#vitroClassGrouppublications> 
    <http://www.w3.org/2000/01/rdf-schema#label> "teadus"@et-EE .
<http://vivoweb.org/ontology#vitroClassGrouporganizations> 
    <http://www.w3.org/2000/01/rdf-schema#label> "organisatsioonid"@et-EE .
<http://vivoweb.org/ontology#vitroClassGroupactivities> 
    <http://www.w3.org/2000/01/rdf-schema#label> "tegevused"@et-EE .

How VIVO supports languages

Language in the data model

The usual form of language support in RDF is to include multiple labels for a single individual, each with a language specifier.

In fact, any set of triples in the data model are considered to be equivalent if they differ only in that the objects are strings with different language specifiers. If language filtering is enabled, VIVO will display the value that matches the user's preferred locale. If no value exactly matches the locale, the closest match is displayed.

Consider these triples in the data:

Code Block
<http://abc.edu/individual/subject1> <http://abc.edu/individual/property1> "coloring" .
<http://abc.edu/individual/subject1> <http://abc.edu/individual/property1> "colouring"@en-UK .
<http://abc.edu/individual/subject1> <http://abc.edu/individual/property1> "colorear"@es .

VIVO would display these values as follows:

User's preferred localedisplayed text
en_UKcolouring
en_CAcolouring
es_MXcolorear
fr_FRcoloring

Language support in VIVO pages

VIVO uses the Java language's built-in framework for Internationalization based on triplets preserved in the graph base. 

Note
iconfalse

"Internationalization" is frequently abbreviated as "I18n", because the word is so long that there are 18 letters between the first "I" and the last "n".

In the I18n framework, displayed text strings are not embedded in the Java classes or in the Freemarker template. Instead, each piece of text is assigned a "key" and the code will ask the framework to provide the text string that is associated with that key. The framework has access to sets of properties files, one set for each supported language, and it will use the appropriate set to get the correct strings.

For example, suppose that we have:

  • The text that will appear in an HTML link, used to cancel the current operation, with the key cancel_link.
  • The title of a page used to upload an image, with the key upload_photo.
  • The text of a prompt message, telling users how big an image must be, with the key minimum_image_dimensions.

The default properties file might show the English language versions of these ttl files, like this:

Code Block
titleExcerpt from

...

/home/src/main/resources/rdf/i18n/

...

en_US/interface-i18n/firsttime/vitro_UiLabel.ttl
prop-data:cancel_link.Vitro
    rdf:type         owl:NamedIndividual ;
    rdf:type         prop:PropertyKey ;
    rdfs:label       "Cancel"@en-US ;
    prop:hasApp      "Vitro" ;
    prop:hasKey      "cancel_link" .

prop-data:upload_photo.Vitro
    rdf:type         owl:NamedIndividual ;
    rdf:type         prop:PropertyKey ;
    rdfs:label       "Upload a photo"@en-US ;
    prop:hasApp      "Vitro" ;
    prop:hasKey      "upload_photo" .
	
prop-data:minimum_image_dimensions.Vitro
    rdf:type         owl:NamedIndividual ;
    rdf:type         prop:PropertyKey ;
    rdfs:label       "Minimum image dimensions: {0} x {1} pixels"@en-US ;
    prop:hasApp      "Vitro" ;
    prop:hasKey      "minimum_image_dimensions" .

Notice that the actual image dimensions are not part of the text string. Instead, placeholders are used to show where the dimensions will appear when they are supplied. This allows us to specify the language-dependent parts of a message in the properties file, while waiting to specify the language-independent parts at run time.

A Spanish language properties file might show the Spanish versions of these properties in a similar manner:

Code Block
titleExcerpt from /home/src/main/resources/rdf/i18n/es/interface-i18n/firsttime/vitro_UiLabel.ttl
prop-data:cancel_link.Vitro
    rdf:type         owl:NamedIndividual ;
    rdf:type         prop:PropertyKey ;
    rdfs:label       "Cancelar"@es ;
    prop:hasApp      "Vitro" ;
    prop:hasKey      "cancel_link" .

prop-data:upload_photo.Vitro
    rdf:type         owl:NamedIndividual ;
    rdf:type         prop:PropertyKey ;
    rdfs:label       "Suba foto"@es ;
    prop:hasApp      "Vitro" ;
    prop:hasKey      "upload_photo" .
	
prop-data:minimum_image_dimensions.Vitro
    rdf:type         owl:NamedIndividual ;
    rdf:type         prop:PropertyKey ;
    rdfs:label       "Dimensiones mínimas de imagen: {0} x {1} pixels"@es ;
    prop:hasApp      "Vitro" ;
    prop:hasKey      "minimum_image_dimensions" .

To use these strings in Java code, start with the I18n class, and the key to the string. Supply values as needed to replace any placeholders in the message.

Code Block
titleUsing I18n strings from Java code
protected String getTitle(String siteName, VitroRequest vreq) {
    return I18n.text(vreq, "upload_image_page_title");
}

private String getPrompt(HttpServletRequest req, int width, int height) {
    return I18n.text(req, "minimum_image_dimensions", width, height);
}

Similarly, using text strings in a Freemarker template begins with the i18n() method.

Code Block
titleUsing I18n strings in a Freemarker template
<#assign text_strings = i18n() >

<a href="../cancel" >
    ${text_strings.cancel_link}
</a>

<p class="note">
    ${text_strings.minimum_image_dimensions(width, height)}
</p>

Here is the appearance of the page in question, in English and in Spanish:

Image AddedImage Added

Structure of the properties files

The properties files that hold text strings are based on the Java I18n framework for resource bundles. Here is a tutorial on resource bundles.

Most text strings will be simple, as shown previously. However, the syntax for expressing text strings is very powerful, and can become complex. As an example, take this text string that handles both singular and plural:

Code Block
titleA complex text string
prop-data:deleted_accounts.Vitro
    rdf:type         owl:NamedIndividual ;
    rdf:type         prop:PropertyKey ;
    rdfs:label       "Deleted {0} {0, choice, 0#accounts|1#account|1<accounts}."@en-US ;
    prop:hasApp      "Vitro" ;
    prop:hasKey      "deleted_accounts" .

The text strings are processed by the Java I18n framework for message formats. Here is a tutorial on message formats. Full details can be found in the description of the MessageFormat class.

Local extension: application vs. theme

The Java I18n framework expects all ui labels translations to be in one location. In VIVO, this has been extended to look in three locations for text strings. First, it looks for ui label translation files in the current theme (for instance, in VIVO - home/src/main/resources/rdf/i18n/en_US/interface-i18n/firsttime/vivo_UiLabel_wilma.ttl). Then, it looks in the main VIVO UI labels file (in VIVO - home/src/main/resources/rdf/i18n/en_US/interface-i18n/firsttime/vivo_UiLabel.ttl), and at the end in Vitro UI labels file (in Vitro - home/src/main/resources/rdf/i18n/en_US/interface-i18n/firsttime/vitro_UiLabel_wilma.ttl)

In each case, the delivered file in English has a corresponding file with the same name followed by and underscore and the name of the locale.  See illustrations below:

Code Block
titleFile names (Estonian)
[VIVO]/languages/et_EE/rdf/i18n/et_EE/applicationMetadata/firsttime/classgroups_labels_et_EE.n3
[VIVO]/languages/et_EE/rdf/i18n/et_EE/applicationMetadata/firsttime/propertygroups_labels_et_EE.n3
[VIVO]/languages/et_EE/rdf/i18n/et_EE/display/everytime/PropertyConfig_et_EE.n3
[VIVO]/languages/et_EE/rdf/i18n/et_EE/display/firsttime/aboutPage_et_EE.n3
[VIVO]/languages/et_EE/rdf/i18n/et_EE/display/firsttime/menu_et_EE.n3
[VIVO]/languages/et_EE/rdf/i18n/et_EE/tbox/firsttime/vitroAnnotations_et_EE.n3

In each file, labels specify text to be used by VIVO.  Each label should be translated and affixed with the appropriate locale tag.  See below:

Code Block
titleSome classgroups_labels (Estonian)
<http://vivoweb.org/ontology#vitroClassGrouppeople> 
    <http://www.w3.org/2000/01/rdf-schema#label> "inimesed"@et-EE .
<http://vivoweb.org/ontology#vitroClassGrouppublications> 
    <http://www.w3.org/2000/01/rdf-schema#label> "teadus"@et-EE .
<http://vivoweb.org/ontology#vitroClassGrouporganizations> 
    <http://www.w3.org/2000/01/rdf-schema#label> "organisatsioonid"@et-EE .
<http://vivoweb.org/ontology#vitroClassGroupactivities> 
    <http://www.w3.org/2000/01/rdf-schema#label> "tegevused"@et-EE .

How VIVO supports languages

Language in the data model

The usual form of language support in RDF is to include multiple labels for a single individual, each with a language specifier.

In fact, any set of triples in the data model are considered to be equivalent if they differ only in that the objects are strings with different language specifiers. If language filtering is enabled, VIVO will display the value that matches the user's preferred locale. If no value exactly matches the locale, the closest match is displayed.

Consider these triples in the data:

Code Block
<http://abc.edu/individual/subject1> <http://abc.edu/individual/property1> "coloring" .
<http://abc.edu/individual/subject1> <http://abc.edu/individual/property1> "colouring"@en-UK .
<http://abc.edu/individual/subject1> <http://abc.edu/individual/property1> "colorear"@es .

VIVO would display these values as follows:

User's preferred localedisplayed text
en_UKcolouring
en_CAcolouring
es_MXcolorear
fr_FRcoloring

Language support in VIVO pages

VIVO uses the Java language's built-in framework for Internationalization. You can find more information in the Java tutorials for resource bundles and properties files.

Note
iconfalse

"Internationalization" is frequently abbreviated as "I18n", because the word is so long that there are 18 letters between the first "I" and the last "n".

In the I18n framework, displayed text strings are not embedded in the Java classes or in the Freemarker template. Instead, each piece of text is assigned a "key" and the code will ask the framework to provide the text string that is associated with that key. The framework has access to sets of properties files, one set for each supported language, and it will use the appropriate set to get the correct strings.

For example, suppose that we have:

  • The text that will appear in an HTML link, used to cancel the current operation, with the key cancel_link.
  • The title of a page used to upload an image, with the key upload_image_page_title.
  • The text of a prompt message, telling users how big an image must be, with the key minimum_image_dimensions.

The default properties file might show the English language versions of these properties, like this:

Code Block
titleExcerpt from all.properties
cancel_link = Cancel
upload_image_page_title = Upload image
minimum_image_dimensions = Minimum image dimensions: {0} x {1} pixels

Notice that the actual image dimensions are not part of the text string. Instead, placeholders are used to show where the dimensions will appear when they are supplied. This allows us to specify the language-dependent parts of a message in the properties file, while waiting to specify the language-independent parts at run time.

A Spanish language properties file might show the Spanish versions of these properties in a similar manner:

Code Block
titleExcerpt from all_es.properties
cancel_link = Cancelar
upload_image_page_title = Subir foto
minimum_image_dimensions = Dimensiones mínimas de imagen: {0} x {1} pixels 

To use these strings in Java code, start with the I18n class, and the key to the string. Supply values as needed to replace any placeholders in the message.

Code Block
titleUsing I18n strings from Java code
protected String getTitle(String siteName, VitroRequest vreq) {
    return I18n.text(vreq, "upload_image_page_title");
}

private String getPrompt(HttpServletRequest req, int width, int height) {
    return I18n.text(req, "minimum_image_dimensions", width, height);
}

Similarly, using text strings in a Freemarker template begins with the i18n() method.

Code Block
titleUsing I18n strings in a Freemarker template
<#assign text_strings = i18n() >

<a href="../cancel" >
    ${text_strings.cancel_link}
</a>

<p class="note">
    ${text_strings.minimum_image_dimensions(width, height)}
</p>

Here is the appearance of the page in question, in English and in Spanish:

Image RemovedImage Removed

Structure of the properties files

The properties files that hold text strings are based on the Java I18n framework for resource bundles. Here is a tutorial on resource bundles.

Most text strings will be simple, as shown previously. However, the syntax for expressing text strings is very powerful, and can become complex. As an example, take this text string that handles both singular and plural:

Code Block
titleA complex text string
deleted_accounts = Deleted {0} {0, choice, 0#accounts |1#account |1<accounts}.

The text strings are processed by the Java I18n framework for message formats. Here is a tutorial on message formats. Full details can be found in the description of the MessageFormat class.

Local extension: application vs. theme

The Java I18n framework expects all properties files to be in one location. In VIVO, this has been extended to look in two locations for text strings. First, it looks for properties files in the current theme directory. Then, it looks in the main application area. This means that you don't need to include all of the basic text strings in your theme. But you can still add or override strings in your theme.

If your VIVO theme is named "frodo", then your UI text strings (using the default bundle name) would be in

  • webapp/themes/frodoin VIVO - home/src/main/resources/rdf/i18n/all.properties
  • webapp/i18n/all.properties

If you specify more than one locale for VIVO, this search pattern becomes longer. For example, if your user has chosen Canadian French as his language/country combination, then these files (if they exist) will be searched for text strings:

  • webapp/themes/frodo/i18n/all_fr_CA.properties
  • webapp/i18n/all_fr_CA.properties
  • webapp/themes/frodo/i18n/all_fr.properties
  • webapp/i18n/all_fr.properties
  • webapp/themes/frodo/i18n/all.properties
  • webapp/i18n/all.properties

When VIVO finds a text string in one of these files, it uses that value, and will not search the remaining files.

Language in Freemarker page templates

Here is some example code from page-home.ftl

  • en_US/interface-i18n/firsttime/vivo_UiLabel_frodo.ttl  
  • in VIVO - home/src/main/resources/rdf/i18n/en_US/interface-i18n/firsttime/vivo_UiLabel.ttl 
  • in Vitro - home/src/main/resources/rdf/i18n/en_US/interface-i18n/firsttime/vitro_UiLabel.ttl 

NOTE: Please use properly hasApp and hasTheme data properties in ttl files, as well as language tags.

If you specify more than one locale for VIVO, this search pattern becomes longer. For example, if your user has chosen UQAM Canadian French as his language/country/private-use subtags combination (fr_CA_x_uqam), then these files (if they exist) will be searched for text strings:

  • in VIVO - home/src/main/resources/rdf/i18n/fr_CA_x_uqam/interface-i18n/firsttime/vivo_UiLabel_frodo.ttl  
  • in VIVO - home/src/main/resources/rdf/i18n/fr_CA_x_uqam/interface-i18n/firsttime/vivo_UiLabel.ttl 
  • in Vitro - home/src/main/resources/rdf/i18n/fr_CA_x_uqam/interface-i18n/firsttime/vitro_UiLabel.ttl 
  • in VIVO - home/src/main/resources/rdf/i18n/fr_CA/interface-i18n/firsttime/vivo_UiLabel_frodo.ttl  
  • in VIVO - home/src/main/resources/rdf/i18n/fr_CA/interface-i18n/firsttime/vivo_UiLabel.ttl 
  • in Vitro - home/src/main/resources/rdf/i18n/fr_CA/interface-i18n/firsttime/vitro_UiLabel.ttl 
  • in VIVO - home/src/main/resources/rdf/i18n/fr/interface-i18n/firsttime/vivo_UiLabel_frodo.ttl  
  • in VIVO - home/src/main/resources/rdf/i18n/fr/interface-i18n/firsttime/vivo_UiLabel.ttl 
  • in Vitro - home/src/main/resources/rdf/i18n/fr/interface-i18n/firsttime/vitro_UiLabel.ttl 
  • in VIVO - home/src/main/resources/rdf/i18n/en_US/interface-i18n/firsttime/vivo_UiLabel_frodo.ttl  
  • in VIVO - home/src/main/resources/rdf/i18n/en_US/interface-i18n/firsttime/vivo_UiLabel.ttl 
  • in Vitro - home/src/main/resources/rdf/i18n/en_US/interface-i18n/firsttime/vitro_UiLabel.ttl

When VIVO finds a text string in one of these files, it uses that value, and will not search the remaining files.

Language in Freemarker page templates

Here is some example code from page-home.ftl

Code Block
titleExcerpt from page-home.ftl
<section id="search-home" role="region">
    <h3>${i18n().intro_searchvivo} <span class="search-filter-selected">filteredSearch</span></h3>
    <fieldset>
        <legend>${i18n().search_form}</legend>
Code Block
titleExcerpt from page-home.ftl
<section id="search-home" role="region">
    <h3>${i18n().intro_searchvivo} <span class="search-filter-selected">filteredSearch</span></h3>
    <fieldset>
        <legend>${i18n().search_form}</legend>
        <form id="search-homepage" action="${urls.search}" name="search-home" role="search" method="post" > 
            <div id="search-home-field">
                <input type="text" name="querytext" class="search-homepage" value="" autocapitalize="off" />
                <input type="submit" value="${i18n().search_button}" class="search" />
                <input type="hidden" name="classgroup"  value="" autocapitalize="off" />
            </div>
            <a class="filter-search filter-default" href="#" title="${i18n().intro_filtersearch}">
                <span class="displace">${i18n().intro_filtersearch}</span>
            </a>
            <ul id="filter-search-nav">
                <li><a class="active" href="">${i18n().all_capitalized}</a></li>
                <@lh.allClassGroupNames vClassGroups! />  
        <form id="search-homepage"   </ul>action="${urls.search}" name="search-home" role="search" method="post" > 
        </form>
    </fieldset>
</section> <!-- #search-home -->

This code lays out all of the formatting and markup, but the actual strings of text are retrieved from the property files, depending on the current language and locale. Here are the English-language strings used by this code:

Code Block
titleEnglish properties used in the example
intro_searchvivo = Search VIVO
search_form = Search form
search_button = Search
intro_filtersearch = Filter search
all_capitalized = All

Language-specific templates

Most Freemaker templates are constructed like the one above; the text is merged with the markup at runtime. In most cases, this results in lower maintenance efforts, since the markup can be re-structured without affecting the text that is displayed.

In some cases, however, the template is predominantly made up of text, with very little markup. In these cases, it is simpler to rewrite the entire template in the chosen language.

The Freemarker framework has anticipated this. When a template is requested, Freemarker will first look for a language-specific version of the template that matches the current locale. So, if the current locale is es_MX, and a request is made for termsOfUse.ftl, Freemarker will look for these template files:

Search order for termsOfUse.ftl

Current locale is es_MX

termsOfUse_es_MX.ftl
termsOfUse_es.ftl
termsOfUse.ftl

Language in Java code

Java code has access to the same language properties that Freemarker accesses. Here is an example of using a language-specific string in Java code:

Code Block
titleExcerpt from UserAccountsAddPageStrategy.java
  FreemarkerEmailMessage email = FreemarkerEmailFactory.createNewMessage(vreq);
  email.addRecipient(TO, page.getAddedAccount().getEmailAddress());
  email.setSubject(i18n.text("account_created_subject", getSiteName()));

The properties files contain this line:

Code Block
titleEnglish language properties used in the example
 account_created_subject = Your {0} account has been created.

Note how the name of the VIVO site is passed as a parameter to the text message.

Language in JSPs

Up through VIVO release 1.10, no attempt has been made to add language support to JSPs.

Language in JavaScript files

To access string properties in JavaScript called from a template, assign the properties to variables in the Freemarker template, and then access those values from the JavaScript.

For example, the template can contain this:

Code Block
titleExcerpt from page-home.ftl
    <script>       
        var i18nStrings = {
            countriesAndRegions: '${i18n().countries_and_regions}',
            statesString: '${i18n().map_states_string}',
    </script> 

And the script can contain this:

<div id="search-home-field">
                <input type="text" name="querytext" class="search-homepage" value="" autocapitalize="off" />
                <input type="submit" value="${i18n().search_button}" class="search" />
                <input type="hidden" name="classgroup"  value="" autocapitalize="off" />
            </div>
            <a class="filter-search filter-default" href="#" title="${i18n().intro_filtersearch}">
                <span class="displace">${i18n().intro_filtersearch}</span>
            </a>
            <ul id="filter-search-nav">
                <li><a class="active" href="">${i18n().all_capitalized}</a></li>
                <@lh.allClassGroupNames vClassGroups! />  
            </ul>
        </form>
    </fieldset>
</section> <!-- #search-home -->

This code lays out all of the formatting and markup, but the actual strings of text are retrieved from the  ttl files, depending on the current language and locale. 

Language-specific templates

Language-specific templates have been completely removed starting from the VIVO/Vitro 1.14.0 release. 

All Freemaker templates are constructed like the one above; the text is merged with the markup at runtime.

Language in Java code

Java code has access to the same language properties that Freemarker accesses. Here is an example of using a language-specific string in Java code:

Code Block
titleExcerpt from UserAccountsAddPageStrategy.java
  FreemarkerEmailMessage email = FreemarkerEmailFactory.createNewMessage(vreq);
  email.addRecipient(TO, page.getAddedAccount().getEmailAddress());
  email.setSubject(i18n.text("account_created_subject", getSiteName()));

The ttl files contain these lines:

Code Block
titleEnglish language properties used in the example
prop-data:account_created_subject.Vitro
    rdf:type         owl:NamedIndividual ;
    rdf:type
Code Block
titleExcerpt from homePageMaps.js
        if ( area == "global" ) {
            text = " " + i18nStrings.countriesAndRegions;
        }
  prop:PropertyKey ;
    rdfs:label   else if ( area == "country" )Your {
0} account has been created."@en-US ;
    prop:hasApp   text  = " Vitro" + i18nStrings.statesString;
        }

i18nChecker

Warning

This functionality was removed in the 1.12 release (

Jira
serverLYRASIS JIRA
serverIdc815ca92-fd23-34c2-8fe3-956808caf8c5
keyVIVO-1753
). Based on the redesign of I18n, a new set of checkers should be created. See:
Jira
serverLYRASIS JIRA
serverIdc815ca92-fd23-34c2-8fe3-956808caf8c5
keyVIVO-1935

i18nChecker is a set of Ruby scripts that are distributed with VIVO, in the utilities/languageSupport/i18nChecker directory. Use them to scan your language properties files and your freemarker templates. The scripts look for common errors in the files.

Scanning language properties files

  • Warn if a specialized file has no default version.
  • Warn about duplicate keys, keys with empty values.
  • Warn about keys that do not appear in the default version.
  • If the "complete" flag is set,
    • Warn if the default version is not found.
    • Warn about missing keys, compared to the default version.

Scanning Freemarker templates

...

prop:hasKey      "account_created_subject" .

Note how the name of the VIVO site is passed as a parameter to the text message.

Language in JSPs

Up through VIVO release 1.14, no attempt has been made to add language support to JSPs.

Language in JavaScript files

To access string properties in JavaScript called from a template, assign the properties to variables in the Freemarker template, and then access those values from the JavaScript.

For example, the template can contain this:

Code Block
titleExcerpt from page-home.ftl
    <script>       
        var i18nStrings = {
            countriesAndRegions: '${i18n().countries_and_regions}',
            statesString: '${i18n().map_states_string}',
    </script> 

And the script can contain this:

Code Block
titleExcerpt from homePageMaps.js
        if ( area == "global" ) {
            text = " " + i18nStrings.countriesAndRegions;
        }
        else if ( area == "country" ) {
            text = " " + i18nStrings.statesString;
        }

...