@@ -28,12 +28,14 @@ pub struct Message {
28
28
/// # Examples
29
29
///
30
30
/// ```
31
- /// use fluent::bundle::FluentBundle;
32
- /// use fluent::types::FluentValue;
31
+ /// use fluent_bundle::bundle::FluentBundle;
32
+ /// use fluent_bundle::resource::FluentResource;
33
+ /// use fluent_bundle::types::FluentValue;
33
34
/// use std::collections::HashMap;
34
35
///
36
+ /// let resource = FluentResource::try_new("intro = Welcome, { $name }.".to_string()).unwrap();
35
37
/// let mut bundle = FluentBundle::new(&["en-US"]);
36
- /// bundle.add_messages("intro = Welcome, { $name }." );
38
+ /// bundle.add_resource(&resource );
37
39
///
38
40
/// let mut args = HashMap::new();
39
41
/// args.insert("name", FluentValue::from("Rustacean"));
@@ -89,7 +91,7 @@ impl<'bundle> FluentBundle<'bundle> {
89
91
/// # Examples
90
92
///
91
93
/// ```
92
- /// use fluent ::bundle::FluentBundle;
94
+ /// use fluent_bundle ::bundle::FluentBundle;
93
95
///
94
96
/// let mut bundle = FluentBundle::new(&["en-US"]);
95
97
/// ```
@@ -120,11 +122,14 @@ impl<'bundle> FluentBundle<'bundle> {
120
122
/// # Examples
121
123
///
122
124
/// ```
123
- /// use fluent::bundle::FluentBundle;
125
+ /// use fluent_bundle::bundle::FluentBundle;
126
+ /// use fluent_bundle::resource::FluentResource;
124
127
///
128
+ /// let resource = FluentResource::try_new("hello = Hi!".to_string()).unwrap();
125
129
/// let mut bundle = FluentBundle::new(&["en-US"]);
126
- /// bundle.add_messages("hello = Hi!" );
130
+ /// bundle.add_resource(&resource );
127
131
/// assert_eq!(true, bundle.has_message("hello"));
132
+ ///
128
133
/// ```
129
134
pub fn has_message ( & self , id : & str ) -> bool {
130
135
self . entries . get_message ( id) . is_some ( )
@@ -140,18 +145,20 @@ impl<'bundle> FluentBundle<'bundle> {
140
145
/// # Examples
141
146
///
142
147
/// ```
143
- /// use fluent::bundle::FluentBundle;
144
- /// use fluent::types::FluentValue;
148
+ /// use fluent_bundle::bundle::FluentBundle;
149
+ /// use fluent_bundle::resource::FluentResource;
150
+ /// use fluent_bundle::types::FluentValue;
145
151
///
152
+ /// let resource = FluentResource::try_new("length = { STRLEN(\"12345\") }".to_string()).unwrap();
146
153
/// let mut bundle = FluentBundle::new(&["en-US"]);
154
+ /// bundle.add_resource(&resource);
147
155
///
148
156
/// // Register a fn that maps from string to string length
149
157
/// bundle.add_function("STRLEN", |positional, _named| match positional {
150
158
/// [Some(FluentValue::String(str))] => Some(FluentValue::Number(str.len().to_string())),
151
159
/// _ => None,
152
160
/// }).unwrap();
153
161
///
154
- /// bundle.add_messages("length = { STRLEN(\"12345\") }").unwrap();
155
162
/// let (value, _) = bundle.format("length", None).unwrap();
156
163
/// assert_eq!(&value, "5");
157
164
/// ```
@@ -182,13 +189,15 @@ impl<'bundle> FluentBundle<'bundle> {
182
189
/// # Examples
183
190
///
184
191
/// ```
185
- /// use fluent::bundle::FluentBundle;
192
+ /// use fluent_bundle::bundle::FluentBundle;
193
+ /// use fluent_bundle::resource::FluentResource;
186
194
///
187
- /// let mut bundle = FluentBundle::new(&["en-US"]);
188
- /// bundle.add_messages("
195
+ /// let resource = FluentResource::try_new("
189
196
/// hello = Hi!
190
197
/// goodbye = Bye!
191
- /// ");
198
+ /// ".to_string()).unwrap();
199
+ /// let mut bundle = FluentBundle::new(&["en-US"]);
200
+ /// bundle.add_resource(&resource);
192
201
/// assert_eq!(true, bundle.has_message("hello"));
193
202
/// ```
194
203
///
@@ -248,12 +257,14 @@ impl<'bundle> FluentBundle<'bundle> {
248
257
/// # Examples
249
258
///
250
259
/// ```
251
- /// use fluent::bundle::FluentBundle;
252
- /// use fluent::types::FluentValue;
260
+ /// use fluent_bundle::bundle::FluentBundle;
261
+ /// use fluent_bundle::resource::FluentResource;
262
+ /// use fluent_bundle::types::FluentValue;
253
263
/// use std::collections::HashMap;
254
264
///
265
+ /// let resource = FluentResource::try_new("intro = Welcome, { $name }.".to_string()).unwrap();
255
266
/// let mut bundle = FluentBundle::new(&["en-US"]);
256
- /// bundle.add_messages("intro = Welcome, { $name }." );
267
+ /// bundle.add_resource(&resource );
257
268
///
258
269
/// let mut args = HashMap::new();
259
270
/// args.insert("name", FluentValue::from("Rustacean"));
@@ -266,14 +277,16 @@ impl<'bundle> FluentBundle<'bundle> {
266
277
/// An example with attributes and no args:
267
278
///
268
279
/// ```
269
- /// use fluent::bundle::FluentBundle;
280
+ /// use fluent_bundle::bundle::FluentBundle;
281
+ /// use fluent_bundle::resource::FluentResource;
270
282
///
271
- /// let mut bundle = FluentBundle::new(&["en-US"]);
272
- /// bundle.add_messages("
283
+ /// let resource = FluentResource::try_new("
273
284
/// hello =
274
285
/// .title = Hi!
275
286
/// .tooltip = This says 'Hi!'
276
- /// ");
287
+ /// ".to_string()).unwrap();
288
+ /// let mut bundle = FluentBundle::new(&["en-US"]);
289
+ /// bundle.add_resource(&resource);
277
290
///
278
291
/// let value = bundle.format("hello.title", None);
279
292
/// assert_eq!(value, Some(("Hi!".to_string(), vec![])));
@@ -291,18 +304,6 @@ impl<'bundle> FluentBundle<'bundle> {
291
304
/// `path` itself as the formatted string. Sometimes, but not always,
292
305
/// these partial failures will emit extra error information in the
293
306
/// second term of the return tuple.
294
- ///
295
- /// ```
296
- /// use fluent::bundle::FluentBundle;
297
- ///
298
- /// // Create a message with bad cyclic reference
299
- /// let mut bundle = FluentBundle::new(&["en-US"]);
300
- /// bundle.add_messages("foo = a { foo } b");
301
- ///
302
- /// // The result falls back to "___"
303
- /// let value = bundle.format("foo", None);
304
- /// assert_eq!(value, Some(("___".to_string(), vec![])));
305
- /// ```
306
307
pub fn format (
307
308
& self ,
308
309
path : & str ,
@@ -354,7 +355,6 @@ impl<'bundle> FluentBundle<'bundle> {
354
355
None
355
356
}
356
357
357
- /// Use [`format`](./struct.FluentBundle.html#method.format) instead.
358
358
pub fn format_message (
359
359
& self ,
360
360
message_id : & str ,
0 commit comments