17 """ Format functions for french (fr) 48 90:
'quatre-vingt-dix' 51 FRACTION_STRING_FR = {
75 """ French helper for nice_number 77 This function formats a float to human understandable functions. Like 78 4.5 becomes "4 et demi" for speech and "4 1/2" for text 81 number (int or float): the float to format 82 speech (bool): format for speech (True) or display (False) 83 denominators (iter of ints): denominators to use, default [1 .. 20] 85 (str): The formatted string. 96 whole = round(number, 3)
98 whole, num, den = result
102 strNumber =
'{:,}'.format(whole)
103 strNumber = strNumber.replace(
",",
" ")
104 strNumber = strNumber.replace(
".",
",")
107 return '{} {}/{}'.format(whole, num, den)
111 strNumber = str(whole)
112 strNumber = strNumber.replace(
".",
",")
114 den_str = FRACTION_STRING_FR[den]
120 strNumber =
'un {}'.format(den_str)
123 strNumber =
'{} {}'.format(num, den_str)
128 strNumber =
'{} et {}'.format(whole, den_str)
131 strNumber =
'{} et 1 {}'.format(whole, den_str)
134 strNumber =
'{} et {} {}'.format(whole, num, den_str)
135 if num > 1
and den != 3:
145 Convert a number to it's spoken equivalent 147 For example, '5.2' would return 'cinq virgule deux' 150 num(float or int): the number to pronounce (under 100) 151 places(int): maximum decimal places to speak 153 (str): The pronounced number 165 tens = int(num-int(num) % 10)
168 if tens > 10
and tens <= 60
and int(num-tens) == 1:
169 result += NUM_STRING_FR[tens] +
"-et-" + NUM_STRING_FR[ones]
171 result +=
"soixante-et-onze" 173 result += NUM_STRING_FR[60] +
"-" 175 result += NUM_STRING_FR[10 + ones]
177 result += NUM_STRING_FR[10] +
"-" + NUM_STRING_FR[ones]
179 result += NUM_STRING_FR[80] +
"-" 181 result += NUM_STRING_FR[10 + ones]
183 result += NUM_STRING_FR[10] +
"-" + NUM_STRING_FR[ones]
185 result += NUM_STRING_FR[tens] +
"-" + NUM_STRING_FR[ones]
188 result +=
"quatre-vingts" 190 result += NUM_STRING_FR[tens]
192 result += NUM_STRING_FR[int(num)]
195 if not num == int(num)
and places > 0:
198 while int(num*place) % 10 > 0
and places > 0:
199 result +=
" " + NUM_STRING_FR[int(num*place) % 10]
207 Format a time to a comfortable human format 209 For example, generate 'cinq heures trente' for speech or '5:30' for 213 dt (datetime): date to format (assumes already in local timezone) 214 speech (bool): format for speech (default/True) or display (False)=Fal 215 use_24hour (bool): output in 24-hour/military or 12-hour format 216 use_ampm (bool): include the am/pm for 12-hour format 218 (str): The formatted time string 222 string = dt.strftime(
"%H:%M")
226 string = dt.strftime(
"%I:%M %p")
229 string = dt.strftime(
"%I:%M")
258 elif dt.minute == 40:
261 elif dt.minute == 45:
264 elif dt.minute == 50:
267 elif dt.minute == 55:
278 elif hour == 1
or hour == 13:
291 speak +=
" moins le quart" 299 speak +=
" de l'après-midi" 300 elif hour > 0
and hour < 12: