This repository was archived by the owner on Jan 29, 2024. It is now read-only.
File tree 2 files changed +28
-8
lines changed
2 files changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -76,14 +76,10 @@ def create_missing_keys
76
76
missing_locales . each { |locale |
77
77
translation = key . translations . first
78
78
79
- # this just replaces the locale part of the file name. should
80
- # be possible to do in a simpler way. gsub, baby.
81
- path = Pathname . new ( translation . file )
82
- dirs , file = path . split
83
- file = file . to_s . split ( "." )
84
- file [ -2 ] = locale
85
- file = file . join ( "." )
86
- path = dirs . join ( file ) . to_s
79
+ # this just replaces the locale part of the file name
80
+ path = translation . file
81
+ . sub ( /(\/ |\. )#{ translation . locale } \. yml$/ , "\\ 1#{ locale } .yml" )
82
+ . sub ( /\/ #{ translation . locale } ([^\/ ]+)\. yml$/ , "/#{ locale } \\ 1.yml" )
87
83
88
84
new_translation = Translation . new ( name : "#{ locale } .#{ key . name } " , file : path )
89
85
add_translation ( new_translation )
Original file line number Diff line number Diff line change @@ -102,6 +102,30 @@ def test_create_missing_translations_in_top_level_file
102
102
assert_nil translation . text
103
103
end
104
104
105
+ def test_create_missing_translations_in_suffix_named_file
106
+ @store . add_translation Translation . new ( name : "da.app_name" , text : "Oversætter" , file : "/tmp/something.foo.da.yml" )
107
+ @store . add_locale ( "en" )
108
+
109
+ @store . create_missing_keys
110
+
111
+ assert ( translation = @store . translations [ "en.app_name" ] )
112
+ assert_equal "en.app_name" , translation . name
113
+ assert_equal "/tmp/something.foo.en.yml" , translation . file
114
+ assert_nil translation . text
115
+ end
116
+
117
+ def test_create_missing_translations_in_prefix_named_file
118
+ @store . add_translation Translation . new ( name : "da.app_name" , text : "Oversætter" , file : "/tmp/da.something.foo.yml" )
119
+ @store . add_locale ( "en" )
120
+
121
+ @store . create_missing_keys
122
+
123
+ assert ( translation = @store . translations [ "en.app_name" ] )
124
+ assert_equal "en.app_name" , translation . name
125
+ assert_equal "/tmp/en.something.foo.yml" , translation . file
126
+ assert_nil translation . text
127
+ end
128
+
105
129
def test_from_yaml
106
130
input = {
107
131
da : {
You can’t perform that action at this time.
0 commit comments