Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file gettextFormat.ml
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768(**************************************************************************)(* 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 *)(**************************************************************************)(** Check string equivalence regarding printf use.
@author Sylvain Le Gall
*)openGettextTypesopenGettextUtils(** [check_format failsafe translation] Returns a translation structure
if all the string contained in the translation are equivalent of str_id,
regarding printf format. If not, replace each string which conflict by
str_id, in the result.
*)letcheck_formatfailsafetranslation=letformat_lst_of_stringstr=letlexbuf=Lexing.from_stringstrinGettextFormat_parser.mainGettextFormat_lexer.tokenlexbufin(* return true in case of problem *)letcheck_format_lst_lstlst1lst2=letcheck_format_lst_lst_auxbs1s2=b||String.compares1s2<>0intryList.fold_left2check_format_lst_lst_auxfalselst1lst2withInvalid_argument_->trueinletcheck_format_lst_strlststr=check_format_lst_lstlst(format_lst_of_stringstr)inletchoose_formatlst_refstr_refstr=ifcheck_format_lst_strlst_refstrthenfail_or_continuefailsafe(FormatInconsistent(str,str_ref))str_refelsestrinmatchtranslationwith|Singular(str_id,str)->letlst_id=format_lst_of_stringstr_idinSingular(str_id,choose_formatlst_idstr_idstr)|Plural(str_id,str_plural,lst)->letlst_id=format_lst_of_stringstr_idinletvalid_str_plural=choose_formatlst_idstr_idstr_pluralinletvalid_lst=matchlstwith|trans_singular::trans_plurals->choose_formatlst_idstr_idtrans_singular::List.map(choose_formatlst_idvalid_str_plural)trans_plurals|[]->[]inPlural(str_id,valid_str_plural,valid_lst)