PageRenderTime 21ms CodeModel.GetById 9ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/locales/fr_fr.d

http://github.com/wilkie/djehuty
D | 185 lines | 152 code | 28 blank | 5 comment | 24 complexity | 83e09d8c736e248167c6bffbba3613c3 MD5 | raw file
  1module locales.fr_fr;
  2
  3import core.locale;
  4
  5import core.time;
  6import core.date;
  7import core.string;
  8import core.definitions;
  9
 10class LocaleFrench_FR : LocaleInterface {
 11	string formatTime(Time time) {
 12		string ret;
 13
 14		long hr, min, sec;
 15		hr = time.hours;
 16		min = time.minutes % 60;
 17		sec = time.seconds % 60;
 18
 19		ret = toStr(hr);
 20		ret ~= ":";
 21
 22		if (min < 10) {
 23			ret ~= "0";
 24		}
 25		ret ~= toStr(min);
 26		ret ~= ":";
 27
 28		if (sec < 10) {
 29			ret ~= "0";
 30		}
 31		ret ~= toStr(sec);
 32
 33		return ret;
 34	}
 35
 36	string formatDate(Date date) {
 37		string ret;
 38
 39		ret = toStr(date.day);
 40		ret ~= " ";
 41
 42		switch(date.month) {
 43			case Month.January:
 44				ret ~= "janvier";
 45				break;
 46			case Month.February:
 47				ret ~= "f\u00e9vier";
 48				break;
 49			case Month.March:
 50				ret ~= "mars";
 51				break;
 52			case Month.April:
 53				ret ~= "avril";
 54				break;
 55			case Month.May:
 56				ret ~= "mai";
 57				break;
 58			case Month.June:
 59				ret ~= "juin";
 60				break;
 61			case Month.July:
 62				ret ~= "juillet";
 63				break;
 64			case Month.August:
 65				ret ~= "ao\u00fbt";
 66				break;
 67			case Month.September:
 68				ret ~= "septembre";
 69				break;
 70			case Month.October:
 71				ret ~= "octobre";
 72				break;
 73			case Month.November:
 74				ret ~= "novembre";
 75				break;
 76			case Month.December:
 77				ret ~= "d\u00e9cembre";
 78				break;
 79			default:
 80				ret ~= "???";
 81				break;
 82		}
 83
 84		ret ~= " " ~ toStr(date.year);
 85
 86		return ret;
 87	}
 88
 89	string formatCurrency(long whole, long scale) {
 90		return formatNumber(whole, scale, 2) ~ " \u20ac";
 91	}
 92
 93	string formatCurrency(double amount) {
 94		return formatNumber(amount) ~ " \u20ac";
 95	}
 96
 97	string formatNumber(long whole, long scale, long round = -1) {
 98		long intPart;
 99		long baseScale;
100		long fracPart;
101
102		// Get integer part of decimal
103		intPart = whole;
104		baseScale = 1;
105		int precision;
106		for (long i; i < scale; i++) {
107			intPart /= 10;
108			baseScale *= 10;
109			precision++;
110		}
111
112		// Get fraction as an integer
113		fracPart = whole % baseScale;
114
115		// Round down 
116		for ( ; precision > round ; precision-- ) {
117			fracPart /= 10;
118		}
119
120		return formatNumber(intPart) ~ "," ~ formatNumber(fracPart);
121	}
122
123	string formatNumber(long value) {
124		if (value == 0) {
125			return "0";
126		}
127
128		string ret;
129		while (value > 0) {
130			long part = value % 1000;
131			value /= 1000;
132			if (ret !is null) {
133				ret = toStr(part) ~ " " ~ ret;
134			}
135			else {
136				ret = toStr(part);
137			}
138		}
139		return ret;
140	}
141
142	string formatNumber(double value) {
143		string ret;
144		long intPart = cast(long)value;
145
146		while (intPart > 0) {
147			long part = intPart % 1000;
148			intPart /= 1000;
149			if (ret !is null) {
150				ret = toStr(part) ~ " " ~ ret;
151			}
152			else {
153				ret = toStr(part);
154			}
155		}
156		ret ~= ",";
157		ret ~= toStr(value);
158	
159		// round last digit
160		bool roundUp = (ret[$-1] >= '5');
161		ret = ret[0..$-1];
162
163		while (roundUp) {
164			if (ret.length == 0) {
165				return "0";
166			}
167			else if (ret[$-1] == ',' || ret[$-1] == '9') {
168				ret = ret[0..$-1];
169				continue;
170			}
171			ret[$-1]++;
172			break;
173		}
174
175		// get rid of useless zeroes (and point if necessary)
176		foreach_reverse(uint i, chr; ret) {
177			if (chr != '0' && chr != ',') {
178				ret = ret[0..i+1];
179				break;
180			}
181		}
182
183		return ret;
184	}
185}