123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104(**************************************************************************)(* ocaml-gettext: a library to translate messages *)(* *)(* Copyright (C) 2003-2008 Sylvain Le Gall <sylvain@le-gall.net> *)(* *)(* This library is free software; you can redistribute it and/or *)(* modify it under the terms of the GNU Lesser General Public *)(* License as published by the Free Software Foundation; either *)(* version 2.1 of the License, or (at your option) any later version; *)(* with the OCaml static compilation exception. *)(* *)(* This library is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)(* Lesser General Public License for more details. *)(* *)(* You should have received a copy of the GNU Lesser General Public *)(* License along with this library; if not, write to the Free Software *)(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *)(* USA *)(**************************************************************************)(** Module type for the function realize.
@author Sylvain Le Gall
*)openGettextTypesopenGettextCategorymoduleGeneric:functor(Translate:GettextTranslate.TRANSLATE_TYPE)(Charset:GettextCharset.CHARSET_TYPE)(Locale:GettextLocale.LOCALE_TYPE)->REALIZE_TYPE=functor(Translate:GettextTranslate.TRANSLATE_TYPE)(Charset:GettextCharset.CHARSET_TYPE)(Locale:GettextLocale.LOCALE_TYPE)->structmoduleMapTranslate=Map.Make(structtypet=textdomain*categoryletcompare(t1,c1)(t2,c2)=matchString.comparet1t2with|0->GettextCategory.comparec1c2|x->xend)letadd_textdomain_categorytmap_translatetextdomaincategory=tryletfilename=GettextDomain.findt(fst(Locale.get_localetcategory))categorytextdomaininletin_enc=letchn=open_in_binfilenameinletmo_header=GettextMo.input_mo_headerchninletmo_informations=GettextMo.input_mo_informationst.failsafechnmo_headerinclose_inchn;mo_informations.content_type_charsetinletout_enc=trymatchMapTextdomain.findtextdomaint.textdomainswith|Somecodeset,_->codeset|None,_->snd(Locale.get_localetcategory)withNot_found->snd(Locale.get_localetcategory)inletrecode=Charset.recode(Charset.createtin_encout_enc)inMapTranslate.add(textdomain,category)(Translate.createtfilenamerecode)map_translatewithDomainFileDoesntExist_filenames->map_translateletadd_textdomaintmap_translatetextdomain=List.fold_left(funmcategory->add_textdomain_categorytmtextdomaincategory)map_translateGettextCategory.categoriesletrealizet=letmap_translate=MapTextdomain.fold(funtextdomain_m->add_textdomaintmtextdomain)t.textdomainsMapTranslate.emptyinletdummy_translate=GettextTranslate.Dummy.createt"(none)"(funs->s)infunprintf_formatoptstrplural_formcategory->lettextdomain=matchoptwithSometextdomain->textdomain|None->t.defaultintryTranslate.translate(MapTranslate.find(textdomain,category)map_translate)printf_formatstrplural_formwithNot_found->GettextTranslate.Dummy.translatedummy_translateprintf_formatstrplural_formend