1
1
use normpath:: PathExt ;
2
2
use std:: fs:: File ;
3
3
use std:: io:: prelude:: * ;
4
- use std:: { collections:: HashMap , path:: Path } ;
4
+ use std:: { collections:: BTreeMap , path:: Path } ;
5
5
6
6
mod atomic_str;
7
7
mod backend;
@@ -19,7 +19,7 @@ pub use minify_key::{
19
19
20
20
type Locale = String ;
21
21
type Value = serde_json:: Value ;
22
- type Translations = HashMap < Locale , Value > ;
22
+ type Translations = BTreeMap < Locale , Value > ;
23
23
24
24
pub fn is_debug ( ) -> bool {
25
25
std:: env:: var ( "RUST_I18N_DEBUG" ) . unwrap_or_else ( |_| "0" . to_string ( ) ) == "1"
@@ -43,9 +43,9 @@ fn merge_value(a: &mut Value, b: &Value) {
43
43
pub fn load_locales < F : Fn ( & str ) -> bool > (
44
44
locales_path : & str ,
45
45
ignore_if : F ,
46
- ) -> HashMap < String , HashMap < String , String > > {
47
- let mut result: HashMap < String , HashMap < String , String > > = HashMap :: new ( ) ;
48
- let mut translations = HashMap :: new ( ) ;
46
+ ) -> BTreeMap < String , BTreeMap < String , String > > {
47
+ let mut result: BTreeMap < String , BTreeMap < String , String > > = BTreeMap :: new ( ) ;
48
+ let mut translations = BTreeMap :: new ( ) ;
49
49
let locales_path = match Path :: new ( locales_path) . normalize ( ) {
50
50
Ok ( p) => p,
51
51
Err ( e) => {
@@ -200,7 +200,7 @@ fn parse_file_v2(key_prefix: &str, data: &serde_json::Value) -> Option<Translati
200
200
// zh-CN: 欢迎
201
201
if text. is_string ( ) {
202
202
let key = format_keys ( & [ key_prefix, key] ) ;
203
- let sub_trs = HashMap :: from ( [ ( key, text. clone ( ) ) ] ) ;
203
+ let sub_trs = BTreeMap :: from ( [ ( key, text. clone ( ) ) ] ) ;
204
204
let sub_value = serde_json:: to_value ( & sub_trs) . unwrap ( ) ;
205
205
206
206
trs. entry ( locale. clone ( ) )
@@ -253,8 +253,8 @@ fn format_keys(keys: &[&str]) -> String {
253
253
. join ( "." )
254
254
}
255
255
256
- fn flatten_keys ( prefix : & str , trs : & Value ) -> HashMap < String , String > {
257
- let mut v = HashMap :: < String , String > :: new ( ) ;
256
+ fn flatten_keys ( prefix : & str , trs : & Value ) -> BTreeMap < String , String > {
257
+ let mut v = BTreeMap :: < String , String > :: new ( ) ;
258
258
let prefix = prefix. to_string ( ) ;
259
259
260
260
match & trs {
0 commit comments