|
Packit |
802e35 |
(**************************************************************************)
|
|
Packit |
802e35 |
(* ocaml-gettext: a library to translate messages *)
|
|
Packit |
802e35 |
(* *)
|
|
Packit |
802e35 |
(* Copyright (C) 2003-2008 Sylvain Le Gall <sylvain@le-gall.net> *)
|
|
Packit |
802e35 |
(* *)
|
|
Packit |
802e35 |
(* This library is free software; you can redistribute it and/or *)
|
|
Packit |
802e35 |
(* modify it under the terms of the GNU Lesser General Public *)
|
|
Packit |
802e35 |
(* License as published by the Free Software Foundation; either *)
|
|
Packit |
802e35 |
(* version 2.1 of the License, or (at your option) any later version; *)
|
|
Packit |
802e35 |
(* with the OCaml static compilation exception. *)
|
|
Packit |
802e35 |
(* *)
|
|
Packit |
802e35 |
(* This library is distributed in the hope that it will be useful, *)
|
|
Packit |
802e35 |
(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
|
|
Packit |
802e35 |
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)
|
|
Packit |
802e35 |
(* Lesser General Public License for more details. *)
|
|
Packit |
802e35 |
(* *)
|
|
Packit |
802e35 |
(* You should have received a copy of the GNU Lesser General Public *)
|
|
Packit |
802e35 |
(* License along with this library; if not, write to the Free Software *)
|
|
Packit |
802e35 |
(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *)
|
|
Packit |
802e35 |
(* USA *)
|
|
Packit |
802e35 |
(**************************************************************************)
|
|
Packit |
802e35 |
|
|
Packit |
802e35 |
|
|
Packit |
802e35 |
open CamomileLibraryDefault.Camomile;;
|
|
Packit |
802e35 |
open GettextTypes;;
|
|
Packit |
802e35 |
|
|
Packit |
802e35 |
(** Error reported when something goes wrong during Camomile initialization.
|
|
Packit |
802e35 |
*)
|
|
Packit |
802e35 |
exception GettextCamomileCreate of string * exn
|
|
Packit |
802e35 |
;;
|
|
Packit |
802e35 |
|
|
Packit |
802e35 |
(** Error reported when something goes wrong during Camomile operation.
|
|
Packit |
802e35 |
*)
|
|
Packit |
802e35 |
exception GettextCamomileRecode of string * exn
|
|
Packit |
802e35 |
;;
|
|
Packit |
802e35 |
|
|
Packit |
802e35 |
(** Charset module, that is derived directly from the camomile library. *)
|
|
Packit |
802e35 |
module Charset : GettextCharset.CHARSET_TYPE =
|
|
Packit |
802e35 |
struct
|
|
Packit |
802e35 |
(**/**)
|
|
Packit |
802e35 |
type encoding = string
|
|
Packit |
802e35 |
type u = {
|
|
Packit |
802e35 |
failsafe : failsafe;
|
|
Packit |
802e35 |
in_enc : CharEncoding.t;
|
|
Packit |
802e35 |
out_enc : CharEncoding.t;
|
|
Packit |
802e35 |
}
|
|
Packit |
802e35 |
|
|
Packit |
802e35 |
let create t in_enc out_enc =
|
|
Packit |
802e35 |
try
|
|
Packit |
802e35 |
{
|
|
Packit |
802e35 |
failsafe = t.GettextTypes.failsafe;
|
|
Packit |
802e35 |
in_enc = CharEncoding.of_name in_enc;
|
|
Packit |
802e35 |
out_enc = CharEncoding.of_name out_enc;
|
|
Packit |
802e35 |
}
|
|
Packit |
802e35 |
with e ->
|
|
Packit |
802e35 |
GettextUtils.fail_or_continue
|
|
Packit |
802e35 |
t.GettextTypes.failsafe
|
|
Packit |
802e35 |
(GettextCamomileCreate(
|
|
Packit |
802e35 |
Printf.sprintf
|
|
Packit |
802e35 |
"Cannot create conversion from %s to %s"
|
|
Packit |
802e35 |
in_enc
|
|
Packit |
802e35 |
out_enc,
|
|
Packit |
802e35 |
e))
|
|
Packit |
802e35 |
{
|
|
Packit |
802e35 |
failsafe = t.GettextTypes.failsafe;
|
|
Packit |
802e35 |
in_enc = CharEncoding.of_name "ISO-8859-1";
|
|
Packit |
802e35 |
out_enc = CharEncoding.of_name "ISO-8859-1";
|
|
Packit |
802e35 |
}
|
|
Packit |
802e35 |
|
|
Packit |
802e35 |
let recode u str =
|
|
Packit |
802e35 |
try
|
|
Packit |
802e35 |
CharEncoding.recode_string u.in_enc u.out_enc str
|
|
Packit |
802e35 |
with e ->
|
|
Packit |
802e35 |
GettextUtils.fail_or_continue
|
|
Packit |
802e35 |
u.failsafe
|
|
Packit |
802e35 |
(GettextCamomileCreate(
|
|
Packit |
802e35 |
Printf.sprintf
|
|
Packit |
802e35 |
"Cannot create convert string %s from %s to %s"
|
|
Packit |
802e35 |
str
|
|
Packit |
802e35 |
(CharEncoding.name_of u.in_enc)
|
|
Packit |
802e35 |
(CharEncoding.name_of u.out_enc),
|
|
Packit |
802e35 |
e))
|
|
Packit |
802e35 |
str
|
|
Packit |
802e35 |
end
|
|
Packit |
802e35 |
;;
|
|
Packit |
802e35 |
|
|
Packit |
802e35 |
(** Implementation based on a Map storage for string. *)
|
|
Packit |
802e35 |
module Map : GettextTypes.REALIZE_TYPE =
|
|
Packit |
802e35 |
GettextRealize.Generic
|
|
Packit |
802e35 |
(GettextTranslate.Map) (* Map translation *)
|
|
Packit |
802e35 |
(Charset) (* Camomile charset *)
|
|
Packit |
802e35 |
(GettextLocale.Posix) (* POSIX locale *)
|
|
Packit |
802e35 |
;;
|
|
Packit |
802e35 |
|
|
Packit |
802e35 |
(** Implementation based on a Hashtbl storage for string. *)
|
|
Packit |
802e35 |
module Hashtbl : GettextTypes.REALIZE_TYPE =
|
|
Packit |
802e35 |
GettextRealize.Generic
|
|
Packit |
802e35 |
(GettextTranslate.Hashtbl) (* Hashtbl translation *)
|
|
Packit |
802e35 |
(Charset) (* Camomile charset *)
|
|
Packit |
802e35 |
(GettextLocale.Posix) (* POSIX locale *)
|
|
Packit |
802e35 |
;;
|
|
Packit |
802e35 |
|
|
Packit |
802e35 |
(** Low memory and fast initialization implementation, files are opened only when needed.
|
|
Packit |
802e35 |
*)
|
|
Packit |
802e35 |
module Open : GettextTypes.REALIZE_TYPE =
|
|
Packit |
802e35 |
GettextRealize.Generic
|
|
Packit |
802e35 |
(GettextTranslate.Open) (* Open translation *)
|
|
Packit |
802e35 |
(Charset) (* Camomile charset *)
|
|
Packit |
802e35 |
(GettextLocale.Posix) (* POSIX locale *)
|
|
Packit |
802e35 |
;;
|
|
Packit |
802e35 |
|