Translate SFX Menu service fields - Target Displayer
Tags: 00code00
, intermediate
, translation
, multilanguage
Last Updated: Mar 15, 2011 12:45
- Description
SFX does not support translation of target names and their fields. With this Target Displayer you can translate target and service public names as well as note and authentication fields at the target, service or portfolio level using translation files. The translation only works at the SFX Menu screen - not using the API nor anywhere else. An alternative (older) Target Displayer which uses inline translations found in the previously mentioned fields is also supplied.
Updated version works with the simplified menu and SFX 4.
- Author: Teemu Nuutinen
- Institution: Helsinki University Library
- Year: 2009
- License: GNU General Public License as published by the Free Software Foundation or the Artistic License version 2.0.
- Short description: Use, modification and distribution of the code are permitted provided the copyright notice, list of conditions and disclaimer appear in all related material.
- Link to terms: GPL, Artistic License
- Skill required for using this code:
intermediate
State
Stable
Programming language
Perl
Software requirements
SFX 4 (SFX 3 compatibility of the updated version is not tested)
Screen captures
Download
Current version:
- L_Translate.tar.gz L_Translate/* Displayers
Older version:
- TranslateLookup Displayer, uses files for translations.
- TranslateInline Displayer, uses inline markup for translations.
Working example
http://sfx.nelliportaali.fi/sfxlcl3/L/A0nSuw
Version 0.04
This updated version fixes compatibility with the simplified menu (getting the language is very inconsistent in SFX) and the target displayer is now inside a directory (SFX 4 requirement).
Installation instructions
Unpack and copy the L_Translate directory to ./lib/Parsers/TargetDisplayer/ (shortcut: td).
L_Translate::Lookup - Translation files
Put translation files in ./config (shortcut: cn).
Filename of the translation file is local_translations.suffix, where suffix is the locale:
- if you are using simplified template menu then it is most likely three characters (eng, fin, ...) and found in ./config/map_languages.config_ file's map_languages section.
- if you are using the advanced menu then the locale is most likely two characters (en, fi, ...) just like the suffixes in translated template files.
Format of the translation file is:
! lines beginning with a ! or # are ignored original field text as seen in SFXAdmin -- translation another -- translation # ignore this comment! <b>User/pass:</b><br/>foo / bar -- <b>Tunnus/Salasana</b><br/>foo / bar ... -- and so on...
Just like in MetaLib!
Usage Instructions
These Displayers translate target and service public names as well as note and authentication fields at the target, service or portfolio level. L_Translate::Lookup uses separate files for translations whereas L_Translate::Inline parses translations directly from the fields (stored using a special markup).
To activate translation for a target service, you must set the Displayer-field to either L_Translate::Lookup or L_Translate::Inline. If the service already uses a displayer, see instructions below.
Using the inline translation is convenient but not recommended because of the limited lenght of the fields (especially in SFX 4). In SFXAdmin Edit Target/Service/Portfolio screen you simply type the translation next to the original text and wrap it in brackets with a your-locale= prefix:
Library[fi=Kirjasto][se=Biblioteket][jp=図書館]
When looking at the menu, the translation is filtered using the current locale. Note: the default language (English?) should never be translated. However, inline translations have a bad downside: the translations "leak" (are not filtered) when using the SFX menu API (or it could be a feature?) and the AZ list. This means targets with portfolios cannot really be translated.
L_Translate::Lookup requires you to edit .config/local_translations.* files, but does not have the same problem. For an example, to translate target's public name put the content of the public name -field and the translated text separated with " -- " in one line to the file:
Original public name -- My translation
Using translation in a target without a Displayer set
Edit the Target's Service, put L_Translate::Lookup (when using translation files or L_Translate::Inline if not) in the Displayer field (which is empty).
Add any translations you want for public names, note and authentication fields in portfolios or service or target to the ./config/local_translations.* files.
Using translation in a target with an existing Displayer
If the target already uses a Displayer, you need to create a subclass of that Displayer. This is very easy and the following example is included.
Assuming a target service already has a displayer like GoogleScholar::Search, you need to create a file in the L_Translate directory, let's name it GoogleScholar.pm. Now edit L_Translate/GoogleScholar.pm and put the following in the file:
package Parsers::TargetDisplayer::L_Translate::GoogleScholar;
use mro 'c3';
use base qw(Parsers::TargetDisplayer::GoogleScholar::Search
Parsers::TargetDisplayer::L_Translate::Lookup);
1;
- On line 1, the GoogleScholar is the name of the file we just created without the .pm suffix.
- On line 3, the GoogleScholar::Search is the original content of the Displayer-field.
Now save the file and replace the Displayer-field value GoogleScholar::Search with L_Translate::GoogleScholar. Similarly you can translate any displayer. The file just tells SFX (Perl) to first use methods from the Lookup-module and then from the original Displayer.
Unfortunately with SFX 3 this is not possible because of the very old version of Perl it uses. For a workaround, please see an older version of this page or look at the perldoc of Lookup.pm or Inline.pm.
Also, some displayers like the above Google Scholar have hardcoded English (or other language) strings within them which cannot be translated without having to completely replace the Displayer.
Known issues
Using the Inline Translation (L_Translate::Inline) the translations are not filtered with the A-Z list, SFX Menu API and (possibly) export files. It is therefore only recommended to be used with targets without portfolios. L_Translate::Lookup has no reported issues.
Older version did not support simplified template menu and hopefully now both are supported (tested briefly before our SFX 4 went into production). Because of the seemingly inconsistent way SFX sets or does not set the locale/language, you might have to try a couple of times to get the correct suffix for the local_translations file.
Comments
This is hopefully a temporary solution. SFX 4 may have better translation support. Here we are, using SFX 4 without built-in support for target/service/portfolio field translations.

