2 // Mono.Posix.Catalog.cs: Wrappers for the libintl library.
5 // Edd Dumbill (edd@usefulinc.com)
7 // (C) 2004 Edd Dumbill
9 // This file implements the low-level syscall interface to the POSIX
12 // This file tries to stay close to the low-level API as much as possible
13 // using enumerations, structures and in a few cases, using existing .NET
16 // Implementation notes:
18 // Since the values for the various constants on the API changes
19 // from system to system (even Linux on different architectures will
20 // have different values), we define our own set of values, and we
21 // use a set of C helper routines to map from the constants we define
22 // to the values of the native OS.
24 // Bitfields are flagged with the [Map] attribute, and a helper program
25 // generates a set of map_XXXX routines that we can call to convert
26 // from our value definitions to the value definitions expected by the
29 // Methods that require tuning are bound as `internal syscal_NAME' methods
30 // and then a `NAME' method is exposed.
34 using System
.Runtime
.InteropServices
;
36 namespace Mono
.Posix
{
38 public class Catalog
{
39 [DllImport("libintl")]
40 static extern IntPtr
bindtextdomain (IntPtr domainname
, IntPtr dirname
);
41 [DllImport("libintl")]
42 static extern IntPtr
bind_textdomain_codeset (IntPtr domainname
,
44 [DllImport("libintl")]
45 static extern IntPtr
textdomain (IntPtr domainname
);
47 public static void Init (String package
, String localedir
)
49 IntPtr ipackage
= Marshal
.StringToHGlobalAuto (package
);
50 IntPtr ilocaledir
= Marshal
.StringToHGlobalAuto (localedir
);
51 IntPtr iutf8
= Marshal
.StringToHGlobalAuto ("UTF-8");
52 bindtextdomain (ipackage
, ilocaledir
);
53 bind_textdomain_codeset (ipackage
, iutf8
);
54 textdomain (ipackage
);
55 Marshal
.FreeHGlobal (ipackage
);
56 Marshal
.FreeHGlobal (ilocaledir
);
57 Marshal
.FreeHGlobal (iutf8
);
60 [DllImport("libintl")]
61 static extern IntPtr
gettext (IntPtr instring
);
63 public static String
GetString (String s
)
65 IntPtr ints
= Marshal
.StringToHGlobalAuto (s
);
66 String t
= Marshal
.PtrToStringAuto (gettext (ints
));
67 Marshal
.FreeHGlobal (ints
);
71 [DllImport("libintl")]
72 static extern IntPtr
ngettext (IntPtr singular
, IntPtr plural
, Int32 n
);
74 public static String
GetPluralString (String s
, String p
, Int32 n
)
76 IntPtr ints
= Marshal
.StringToHGlobalAuto (s
);
77 IntPtr intp
= Marshal
.StringToHGlobalAuto (p
);
78 String t
= Marshal
.PtrToStringAnsi (ngettext (ints
, intp
, n
));
79 Marshal
.FreeHGlobal (ints
);
80 Marshal
.FreeHGlobal (intp
);