summaryrefslogtreecommitdiffstats
path: root/src/catalog.d
blob: fae44ac259113a8c4fa3b9d7f9acd66e8360de0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module catalog;

import std.string;

static extern (C) char* setlocale(int category, char* locale);
static extern (C) char* bindtextdomain(char* domainname, char* localedir);
static extern (C) char* bind_textdomain_codeset(char* domainname, char* localedir);
static extern (C) char* textdomain(char* domainname);
static extern (C) char* gettext(char* instring);
static extern (C) char* ngettext(char* singular, char* plural, int n);
	
public static class Catalog
{
	public static void Init(char[] packageid, char[] localedir)
	{
		setlocale(6, "");
		bindtextdomain(std.string.toStringz(packageid), std.string.toStringz(localedir));
		bind_textdomain_codeset(std.string.toStringz(packageid), "UTF-8");
		textdomain(std.string.toStringz(packageid));
	}

	public static char[] GetString(char[] s)
	{
		return std.string.toString(gettext(std.string.toStringz(s)));
	}

	public static char[] GetPluralString(char[] s, char[] p, int n)
	{
		return std.string.toString(ngettext(std.string.toStringz(s), std.string.toStringz(p), n));
	}
}