PageRenderTime 28ms CodeModel.GetById 16ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/core/locale.d

http://github.com/wilkie/djehuty
D | 80 lines | 55 code | 15 blank | 10 comment | 0 complexity | 3f51bdc0e7df4af875b540f12036733b MD5 | raw file
 1/*
 2 * locale.d
 3 *
 4 * This module handles locale and internationalization.
 5 *
 6 * Author: Dave Wilkinson
 7 * Originated: September 15th, 2009
 8 *
 9 */
10
11module core.locale;
12
13import core.time;
14import core.date;
15import core.string;
16import core.definitions;
17
18// Supported Locales
19import locales.all;
20
21enum LocaleId : uint {
22	English_US,
23	English_GB,
24	French_FR,
25}
26
27class Locale {
28static:
29
30	LocaleId id() {
31		return _localeId;
32	}
33
34	void id(LocaleId value) {
35		_localeId = value;
36		switch(_localeId) {
37			default:
38			case LocaleId.English_US:
39				_localeEngine = new LocaleEnglish_US();
40				break;
41			case LocaleId.French_FR:
42				_localeEngine = new LocaleFrench_FR();
43				break;
44		}
45	}
46
47	string formatNumber(double value) {
48		return _localeEngine.formatNumber(value);
49	}
50
51	string formatCurrency(long fixed, long scale) {
52		return _localeEngine.formatCurrency(fixed, scale);
53	}
54
55	string formatCurrency(double amount) {
56		return _localeEngine.formatCurrency(amount);
57	}
58
59	string formatTime(Time time) {
60		return _localeEngine.formatTime(time);
61	}
62
63	string formatDate(Date date) {
64		return _localeEngine.formatDate(date);
65	}
66
67private:
68
69	LocaleId _localeId = LocaleId.English_US;
70	LocaleInterface _localeEngine;
71}
72
73interface LocaleInterface {
74	string formatTime(Time time);
75	string formatDate(Date date);
76	string formatNumber(double value);
77	string formatNumber(long fixed, long scale, long round);
78	string formatCurrency(double amount);
79	string formatCurrency(long fixed, long scale);
80}