@@ -39,20 +39,20 @@ Usage
3939-----
4040
4141To generate translations from this Python libary, you start with the
42- ` MessageContext ` class:
42+ ` FluentBundle ` class:
4343
44- >>> from fluent.context import MessageContext
44+ >>> from fluent.bundle import FluentBundle
4545
4646You pass a list of locales to the constructor - the first being the desired
4747locale, with fallbacks after that:
4848
49- >>> context = MessageContext (["en-US"])
49+ >>> bundle = FluentBundle (["en-US"])
5050
5151
5252You must then add messages. These would normally come from a ` .ftl ` file stored
5353on disk, here we will just add them directly:
5454
55- >>> context .add_messages("""
55+ >>> bundle .add_messages("""
5656 ... welcome = Welcome to this great app!
5757 ... greet-by-name = Hello, { $name }!
5858 ... """)
@@ -64,17 +64,17 @@ implementation tries hard to recover from any formatting errors and generate the
6464most human readable representation of the value. The ` format ` method therefore
6565returns a tuple containing ` (translated string, errors) ` , as below.
6666
67- >>> translated, errs = context .format('welcome')
67+ >>> translated, errs = bundle .format('welcome')
6868 >>> translated
6969 "Welcome to this great app!"
7070 >>> errs
7171 []
7272
73- >>> translated, errs = context .format('greet-by-name', {'name': 'Jane'})
73+ >>> translated, errs = bundle .format('greet-by-name', {'name': 'Jane'})
7474 >>> translated
7575 'Hello, \u2068Jane\u2069!'
7676
77- >>> translated, errs = context .format('greet-by-name', {})
77+ >>> translated, errs = bundle .format('greet-by-name', {})
7878 >>> translated
7979 'Hello, \u2068name\u2069!'
8080 >>> errs
@@ -85,7 +85,7 @@ are Unicode bidi isolation characters that help to ensure that the interpolated
8585strings are handled correctly in the situation where the text direction of the
8686substitution might not match the text direction of the localized text. These
8787characters can be disabled if you are sure that is not possible for your app by
88- passing ` use_isolating=False ` to the ` MessageContext ` constructor.
88+ passing ` use_isolating=False ` to the ` FluentBundle ` constructor.
8989
9090Python 2
9191--------
@@ -105,23 +105,23 @@ Numbers
105105When rendering translations, Fluent passes any numeric arguments (int or float)
106106through locale-aware formatting functions:
107107
108- >>> context .add_messages("show-total-points = You have { $points } points.")
109- >>> val, errs = context .format("show-total-points", {'points': 1234567})
108+ >>> bundle .add_messages("show-total-points = You have { $points } points.")
109+ >>> val, errs = bundle .format("show-total-points", {'points': 1234567})
110110 >>> val
111111 'You have 1,234,567 points.'
112112
113113
114114You can specify your own formatting options on the arguments passed in by
115115wrapping your numeric arguments with ` fluent.types.fluent_number ` :
116116
117- >>> from fluent.types import fluent_number
117+ >>> from fluent.bundle. types import fluent_number
118118 >>> points = fluent_number(1234567, useGrouping=False)
119- >>> context .format("show-total-points", {'points': points})[0]
119+ >>> bundle .format("show-total-points", {'points': points})[0]
120120 'You have 1234567 points.'
121121
122122 >>> amount = fluent_number(1234.56, style="currency", currency="USD")
123- >>> context .add_messages("your-balance = Your balance is { $amount }")
124- >>> context .format("your-balance", {'amount': amount})[0]
123+ >>> bundle .add_messages("your-balance = Your balance is { $amount }")
124+ >>> bundle .format("your-balance", {'amount': amount})[0]
125125 'Your balance is $1,234.56'
126126
127127Thee options available are defined in the Fluent spec for
@@ -136,14 +136,14 @@ Python `dateime.datetime` and `datetime.date` objects are also passed through
136136locale aware functions:
137137
138138 >>> from datetime import date
139- >>> context .add_messages("today-is = Today is { $today }")
140- >>> val, errs = context .format("today-is", {"today": date.today() })
139+ >>> bundle .add_messages("today-is = Today is { $today }")
140+ >>> val, errs = bundle .format("today-is", {"today": date.today() })
141141 >>> val
142142 'Today is Jun 16, 2018'
143143
144144You can explicitly call the ` DATETIME ` builtin to specify options:
145145
146- >>> context .add_messages('today-is = Today is { DATETIME($today, dateStyle: "short") }')
146+ >>> bundle .add_messages('today-is = Today is { DATETIME($today, dateStyle: "short") }')
147147
148148See the [ DATETIME
149149docs] ( https://projectfluent.org/fluent/guide/functions.html#datetime ) . However,
@@ -153,12 +153,12 @@ currently the only supported options to `DATETIME` are:
153153* ` dateStyle ` and ` timeStyle ` which are [ proposed
154154 additions] ( https://github.com/tc39/proposal-ecma402-datetime-style ) to the ECMA i18n spec.
155155
156- To specify options from Python code, use ` fluent.types.fluent_date ` :
156+ To specify options from Python code, use ` fluent.bundle. types.fluent_date ` :
157157
158- >>> from fluent.types import fluent_date
158+ >>> from fluent.bundle. types import fluent_date
159159 >>> today = date.today()
160160 >>> short_today = fluent_date(today, dateStyle='short')
161- >>> val, errs = context .format("today-is", {"today": short_today })
161+ >>> val, errs = bundle .format("today-is", {"today": short_today })
162162 >>> val
163163 'Today is 6/17/18'
164164
@@ -180,8 +180,8 @@ You can also specify timezone for displaying `datetime` objects in two ways:
180180 >>> utcnow
181181 datetime.datetime(2018, 6, 17, 12, 15, 5, 677597)
182182
183- >>> context .add_messages("now-is = Now is { $now }")
184- >>> val, errs = context .format("now-is",
183+ >>> bundle .add_messages("now-is = Now is { $now }")
184+ >>> val, errs = bundle .format("now-is",
185185 ... {"now": fluent_date(utcnow,
186186 ... timeZone="Europe/Moscow",
187187 ... dateStyle="medium",
@@ -194,7 +194,7 @@ Custom functions
194194----------------
195195
196196You can add functions to the ones available to FTL authors by passing
197- a ` functions ` dictionary to the ` MessageContext ` constructor:
197+ a ` functions ` dictionary to the ` FluentBundle ` constructor:
198198
199199
200200 >>> import platform
@@ -204,24 +204,24 @@ a `functions` dictionary to the `MessageContext` constructor:
204204 ... 'Darwin': 'mac',
205205 ... 'Windows': 'windows'}.get(platform.system(), 'other')
206206
207- >>> context = MessageContext (['en-US'], functions={'OS': os_name})
208- >>> context .add_messages("""
207+ >>> bundle = FluentBundle (['en-US'], functions={'OS': os_name})
208+ >>> bundle .add_messages("""
209209 ... welcome = { OS() ->
210210 ... [linux] Welcome to Linux
211211 ... [mac] Welcome to Mac
212212 ... [windows] Welcome to Windows
213213 ... *[other] Welcome
214214 ... }
215215 ... """)
216- >>> print(context .format('welcome')[0]
216+ >>> print(bundle .format('welcome')[0]
217217 Welcome to Linux
218218
219219These functions can accept positioal and keyword arguments (like the ` NUMBER `
220220and ` DATETIME ` builtins), and in this case must accept the following types of
221221arguments:
222222
223223* unicode strings (i.e. ` unicode ` on Python 2, ` str ` on Python 3)
224- * ` fluent.types.FluentType ` subclasses, namely:
224+ * ` fluent.bundle. types.FluentType ` subclasses, namely:
225225 * ` FluentNumber ` - ` int ` , ` float ` or ` Decimal ` objects passed in externally,
226226 or expressed as literals, are wrapped in these. Note that these objects also
227227 subclass builtin ` int ` , ` float ` or ` Decimal ` , so can be used as numbers in
0 commit comments