1515
1616
1717def test_en_basic ():
18- bundle = fluent .Bundle ("en" , data_dir / "en.ftl" )
18+ bundle = fluent .Bundle ("en" , [ data_dir / "en.ftl" ] )
1919 assert bundle .get_translation ("hello-world" ) == "Hello World"
2020
2121
2222def test_en_basic_str_path ():
23- bundle = fluent .Bundle ("en" , str (data_dir / "en.ftl" ))
23+ bundle = fluent .Bundle ("en" , [ str (data_dir / "en.ftl" )] )
2424 assert bundle .get_translation ("hello-world" ) == "Hello World"
2525
2626
2727def test_en_basic_with_named_arguments ():
2828 bundle = fluent .Bundle (
2929 language = "en" ,
30- ftl_filename = data_dir / "en.ftl" ,
30+ ftl_filenames = [ data_dir / "en.ftl" ] ,
3131 )
3232 assert bundle .get_translation ("hello-world" ) == "Hello World"
3333
3434
3535def test_en_with_variables ():
36- bundle = fluent .Bundle ("en" , data_dir / "en.ftl" )
36+ bundle = fluent .Bundle ("en" , [ data_dir / "en.ftl" ] )
3737 assert (
3838 bundle .get_translation ("hello-user" , variables = {"user" : "Bob" })
3939 == f"Hello, { BIDI_OPEN } Bob{ BIDI_CLOSE } "
4040 )
4141
4242
4343def test_en_with_variables_use_isolating_off ():
44- bundle = fluent .Bundle ("en" , data_dir / "en.ftl" )
44+ bundle = fluent .Bundle ("en" , [ data_dir / "en.ftl" ] )
4545 assert (
4646 bundle .get_translation (
4747 "hello-user" ,
@@ -66,7 +66,7 @@ def test_en_with_variables_use_isolating_off():
6666 ),
6767)
6868def test_variables_of_different_types (description , identifier , variables , expected ):
69- bundle = fluent .Bundle ("en" , data_dir / "en.ftl" )
69+ bundle = fluent .Bundle ("en" , [ data_dir / "en.ftl" ] )
7070
7171 result = bundle .get_translation (identifier , variables = variables )
7272
@@ -75,7 +75,7 @@ def test_variables_of_different_types(description, identifier, variables, expect
7575
7676def test_invalid_language ():
7777 with pytest .raises (ValueError ) as exc_info :
78- fluent .Bundle ("$" , "" )
78+ fluent .Bundle ("$" , [] )
7979
8080 assert str (exc_info .value ) == "Invalid language: '$'"
8181
@@ -89,7 +89,7 @@ def test_invalid_language():
8989 ),
9090)
9191def test_invalid_variable_keys_raise_type_error (key ):
92- bundle = fluent .Bundle ("en" , data_dir / "en.ftl" )
92+ bundle = fluent .Bundle ("en" , [ data_dir / "en.ftl" ] )
9393
9494 with pytest .raises (TypeError , match = "Variable key not a str, got" ):
9595 bundle .get_translation ("hello-user" , variables = {key : "Bob" })
@@ -104,20 +104,20 @@ def test_invalid_variable_keys_raise_type_error(key):
104104 ),
105105)
106106def test_invalid_variable_values_use_key_instead (value ):
107- bundle = fluent .Bundle ("en" , data_dir / "en.ftl" )
107+ bundle = fluent .Bundle ("en" , [ data_dir / "en.ftl" ] )
108108
109109 result = bundle .get_translation ("hello-user" , variables = {"user" : value })
110110
111111 assert result == f"Hello, { BIDI_OPEN } user{ BIDI_CLOSE } "
112112
113113
114114def test_fr_basic ():
115- bundle = fluent .Bundle ("fr" , data_dir / "fr.ftl" )
115+ bundle = fluent .Bundle ("fr" , [ data_dir / "fr.ftl" ] )
116116 assert bundle .get_translation ("hello-world" ) == "Bonjour le monde!"
117117
118118
119119def test_fr_with_args ():
120- bundle = fluent .Bundle ("fr" , data_dir / "fr.ftl" )
120+ bundle = fluent .Bundle ("fr" , [ data_dir / "fr.ftl" ] )
121121 assert (
122122 bundle .get_translation ("hello-user" , variables = {"user" : "Bob" })
123123 == f"Bonjour, { BIDI_OPEN } Bob{ BIDI_CLOSE } !"
@@ -135,22 +135,34 @@ def test_fr_with_args():
135135 ),
136136)
137137def test_selector (number , expected ):
138- bundle = fluent .Bundle ("en" , data_dir / "en.ftl" )
138+ bundle = fluent .Bundle ("en" , [ data_dir / "en.ftl" ] )
139139
140140 result = bundle .get_translation ("with-selector" , variables = {"number" : number })
141141
142142 assert result == expected
143143
144144
145+ def test_new_overwrites_old ():
146+ bundle = fluent .Bundle (
147+ "en" ,
148+ [data_dir / "fr.ftl" , data_dir / "en_hello.ftl" ],
149+ )
150+ assert bundle .get_translation ("hello-world" ) == "Hello World"
151+ assert (
152+ bundle .get_translation ("hello-user" , variables = {"user" : "Bob" })
153+ == f"Bonjour, { BIDI_OPEN } Bob{ BIDI_CLOSE } !"
154+ )
155+
156+
145157def test_id_not_found ():
146- bundle = fluent .Bundle ("fr" , data_dir / "fr.ftl" )
158+ bundle = fluent .Bundle ("fr" , [ data_dir / "fr.ftl" ] )
147159 with pytest .raises (ValueError ):
148160 bundle .get_translation ("missing" , variables = {"user" : "Bob" })
149161
150162
151163def test_file_not_found ():
152164 with pytest .raises (FileNotFoundError ):
153- fluent .Bundle ("fr" , data_dir / "none.ftl" )
165+ fluent .Bundle ("fr" , [ data_dir / "none.ftl" ] )
154166
155167
156168@pytest .mark .parametrize ("pass_strict_argument_explicitly" , (True , False ))
@@ -159,7 +171,7 @@ def test_parses_other_parts_of_file_that_contains_errors_in_non_strict_mode(
159171):
160172 kwargs = dict (strict = False ) if pass_strict_argument_explicitly else {}
161173
162- bundle = fluent .Bundle ("fr" , data_dir / "errors.ftl" , ** kwargs )
174+ bundle = fluent .Bundle ("fr" , [ data_dir / "errors.ftl" ] , ** kwargs )
163175 translation = bundle .get_translation ("valid-message" )
164176
165177 assert translation == "I'm valid."
@@ -169,7 +181,7 @@ def test_raises_parser_error_on_file_that_contains_errors_in_strict_mode():
169181 filename = data_dir / "errors.ftl"
170182
171183 with pytest .raises (fluent .ParserError ) as exc_info :
172- fluent .Bundle ("fr" , filename , strict = True )
184+ fluent .Bundle ("fr" , [ filename ] , strict = True )
173185
174186 message = str (exc_info .value )
175187
@@ -201,31 +213,31 @@ def test_parser_error_str():
201213
202214
203215def test_basic_attribute_access ():
204- bundle = fluent .Bundle ("en" , data_dir / "attributes.ftl" )
216+ bundle = fluent .Bundle ("en" , [ data_dir / "attributes.ftl" ] )
205217 assert bundle .get_translation ("welcome-message.title" ) == "Welcome to our site"
206218
207219
208220def test_regular_message_still_works_with_attributes ():
209221 """Test that accessing the main message value still works when it has attributes."""
210- bundle = fluent .Bundle ("en" , data_dir / "attributes.ftl" )
222+ bundle = fluent .Bundle ("en" , [ data_dir / "attributes.ftl" ] )
211223 assert bundle .get_translation ("welcome-message" ) == "Welcome!"
212224
213225
214226def test_multiple_attributes_on_same_message ():
215- bundle = fluent .Bundle ("en" , data_dir / "attributes.ftl" )
227+ bundle = fluent .Bundle ("en" , [ data_dir / "attributes.ftl" ] )
216228 assert bundle .get_translation ("login-input.placeholder" ) == "email@example.com"
217229 assert bundle .get_translation ("login-input.aria-label" ) == "Login input value"
218230 assert bundle .get_translation ("login-input.title" ) == "Type your login email"
219231
220232
221233def test_attribute_with_variables ():
222- bundle = fluent .Bundle ("en" , data_dir / "attributes.ftl" )
234+ bundle = fluent .Bundle ("en" , [ data_dir / "attributes.ftl" ] )
223235 result = bundle .get_translation ("greeting.formal" , variables = {"name" : "Alice" })
224236 assert result == f"Hello, { BIDI_OPEN } Alice{ BIDI_CLOSE } "
225237
226238
227239def test_attribute_with_variables_use_isolating_off ():
228- bundle = fluent .Bundle ("en" , data_dir / "attributes.ftl" )
240+ bundle = fluent .Bundle ("en" , [ data_dir / "attributes.ftl" ] )
229241 result = bundle .get_translation (
230242 "greeting.informal" ,
231243 variables = {"name" : "Bob" },
@@ -235,27 +247,27 @@ def test_attribute_with_variables_use_isolating_off():
235247
236248
237249def test_attribute_on_message_without_main_value ():
238- bundle = fluent .Bundle ("en" , data_dir / "attributes.ftl" )
250+ bundle = fluent .Bundle ("en" , [ data_dir / "attributes.ftl" ] )
239251 assert bundle .get_translation ("form-button.submit" ) == "Submit Form"
240252 assert bundle .get_translation ("form-button.cancel" ) == "Cancel"
241253 assert bundle .get_translation ("form-button.reset" ) == "Reset Form"
242254
243255
244256def test_message_without_value_raises_error ():
245257 """Test that accessing a message without a value (only attributes) raises an error."""
246- bundle = fluent .Bundle ("en" , data_dir / "attributes.ftl" )
258+ bundle = fluent .Bundle ("en" , [ data_dir / "attributes.ftl" ] )
247259 with pytest .raises (ValueError , match = "form-button - Message has no value" ):
248260 bundle .get_translation ("form-button" )
249261
250262
251263def test_missing_message_with_attribute_syntax_raises_error ():
252- bundle = fluent .Bundle ("en" , data_dir / "attributes.ftl" )
264+ bundle = fluent .Bundle ("en" , [ data_dir / "attributes.ftl" ] )
253265 with pytest .raises (ValueError , match = "nonexistent not found" ):
254266 bundle .get_translation ("nonexistent.title" )
255267
256268
257269def test_missing_attribute_raises_error ():
258- bundle = fluent .Bundle ("en" , data_dir / "attributes.ftl" )
270+ bundle = fluent .Bundle ("en" , [ data_dir / "attributes.ftl" ] )
259271 with pytest .raises (
260272 ValueError ,
261273 match = "welcome-message.nonexistent - Attribute 'nonexistent' not found on message 'welcome-message'" ,
@@ -274,5 +286,5 @@ def test_missing_attribute_raises_error():
274286 ),
275287)
276288def test_attribute_and_message_access_parameterized (identifier , expected ):
277- bundle = fluent .Bundle ("en" , data_dir / "attributes.ftl" )
289+ bundle = fluent .Bundle ("en" , [ data_dir / "attributes.ftl" ] )
278290 assert bundle .get_translation (identifier ) == expected
0 commit comments