Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:user_advanced:gs2_format [2014/09/08 12:43] (current)
Line 1: Line 1:
 +====== Advanced Greenstone 2 Formatting Topics ======
 +
 +===== Displaying Language Names instead of Codes =====
 +
 +Often documents will have language metadata in two letter codes, such as en, fr, ja, or maybe three letter codes, like eng, fre, ger.
 +
 +Lets say our documents have two letter language codes, in the dc.Language metadata field. And we want to display this in our search results. We can add //​[dc.Language]//​ to the SearchVList format statement.
 +
 +If we want to display the name of the language instead of the code, we can use //​[format:​dc.Language]//​.
 +
 +Internally, //​[format:​dc.Language]//​ will get turned into a macro: //​_iso639:​iso639xx_//​ where xx is the two letter code. For example, if the language was en, then the macro will be //​_iso639:​iso639en_//​.
 +These macros are defined in languages.dm in the macros folder.
 +
 +=== Displaying language names in other languages ===
 +Greenstone only provides English versions of the language names. You can add macro definitions for other languages into the languages.dm file by copying the rule and adding a language argument. For example:
 +
 +//​_iso639en_ [l=fr] {Anglais}\\
 +_iso639en_ [l=es] {Inglés}//
 +
 +=== Using three letter codes ===
 +
 +Greenstone only provides a mapping for two letter codes. If you are using three letter codes, you can add in new mappings to the languages.dm file in a similar way.
 +
 +Add for example:
 +
 +//​_iso639eng_ {English}\\
 +_iso639fre_ {French}//
 +
 +Alternatively,​ you can use //​_iso639eng_ {_iso639en_}//​ which will map the three letter code to the two letter code. This is useful if you have defined rules for displaying the codes in different languages.
 +
 +=== Language codes that are not in Language metadata ===
 +
 +This formatting trick in Greenstone only works for metadata elements called Language (or with a namespace, e.g. dc.Language). There is a hard coded test for '​Language'​ in the source code. What can you do if your language codes are in a different metadata element?
 +
 +This applies too if you have built a classifier on Language metadata. When you are displaying the bookshelf of the classifier, the metadata you are outputting is no longer called //​Language//,​ it is called //Title//. //​[format:​Title]//​ will not do the same thing as //​[format:​Language]//​.
 +
 +When //​[format:​MetaName]//​ is processed by the source code, the metadata name (MetaName) is tested. If it is Date, then we output //​_format:​date_(xxx)//​ where xxx is the date value. If the metadata name is Language, we output //​_iso939:​iso639xx_//​ where xx is the language value.
 +
 +For all others, we output //​_format:​MetaName_(xxx)//​ where MetaName is the metadata name and xxx is the value. We can define this macro to make it use the language code rules. ​
 +
 +In the collection'​s extra.dm, or in GLI's Collection Specific Macros part of the Format panel, add lines like the following.
 +
 +This example will turn [format:​Title] into a language macro, and can be used for displaying language names in a bookshelf of a classifier built on the language codes.
 +
 +//package format\\
 +\\
 +_Title_ {_iso639:​iso639_1__}\\
 +//
 +
 +The //_1_// part represents the (first) argument passed in to the macro.
 +