@@ -11,6 +11,7 @@ use fluent_fallback::{
1111 types:: { L10nKey , ResourceId } ,
1212 Localization , LocalizationError ,
1313} ;
14+ use rustc_hash:: FxHashSet ;
1415use std:: cell:: RefCell ;
1516use std:: rc:: Rc ;
1617use unic_langid:: { langid, LanguageIdentifier } ;
@@ -55,7 +56,7 @@ impl LocalesProvider for Locales {
5556// lack of GATs, these have to own members instead of taking slices.
5657struct BundleIter {
5758 locales : <Vec < LanguageIdentifier > as IntoIterator >:: IntoIter ,
58- res_ids : Vec < ResourceId > ,
59+ res_ids : FxHashSet < ResourceId > ,
5960}
6061
6162impl Iterator for BundleIter {
@@ -132,11 +133,19 @@ impl BundleGenerator for ResourceManager {
132133 type Iter = BundleIter ;
133134 type Stream = BundleIter ;
134135
135- fn bundles_iter ( & self , locales : Self :: LocalesIter , res_ids : Vec < ResourceId > ) -> Self :: Iter {
136+ fn bundles_iter (
137+ & self ,
138+ locales : Self :: LocalesIter ,
139+ res_ids : FxHashSet < ResourceId > ,
140+ ) -> Self :: Iter {
136141 BundleIter { locales, res_ids }
137142 }
138143
139- fn bundles_stream ( & self , locales : Self :: LocalesIter , res_ids : Vec < ResourceId > ) -> Self :: Stream {
144+ fn bundles_stream (
145+ & self ,
146+ locales : Self :: LocalesIter ,
147+ res_ids : FxHashSet < ResourceId > ,
148+ ) -> Self :: Stream {
140149 BundleIter { locales, res_ids }
141150 }
142151}
@@ -488,3 +497,22 @@ async fn localization_handle_state_changes_mid_async() {
488497
489498 bundles. format_value ( "key" , None , & mut errors) . await ;
490499}
500+
501+ #[ test]
502+ fn localization_duplicate_resources ( ) {
503+ let resource_ids: Vec < ResourceId > =
504+ vec ! [ "test.ftl" . into( ) , "test2.ftl" . into( ) , "test2.ftl" . into( ) ] ;
505+ let locales = Locales :: new ( vec ! [ langid!( "pl" ) , langid!( "en-US" ) ] ) ;
506+ let res_mgr = ResourceManager ;
507+ let mut errors = vec ! [ ] ;
508+
509+ let loc = Localization :: with_env ( resource_ids, true , locales, res_mgr) ;
510+ let bundles = loc. bundles ( ) ;
511+
512+ let value = bundles
513+ . format_value_sync ( "hello-world" , None , & mut errors)
514+ . unwrap ( ) ;
515+ assert_eq ! ( value, Some ( Cow :: Borrowed ( "Hello World [pl]" ) ) ) ;
516+
517+ assert_eq ! ( errors. len( ) , 0 , "There were no errors" ) ;
518+ }
0 commit comments