@@ -80,31 +80,46 @@ public PlaceholderUtil(List<Language> supportedLanguages, List<com.crowdin.clien
80
80
this .basePath = basePath ;
81
81
}
82
82
83
- public List <String > format (List <File > sources , List <String > toFormat , boolean onProjectLangs ) {
83
+ public List <String > format (List <File > sources , List <String > toFormat ) {
84
84
if (sources == null || toFormat == null ) {
85
85
return new ArrayList <>();
86
86
}
87
87
List <String > res = new ArrayList <>();
88
88
for (String str : toFormat ) {
89
- res .addAll (this .format (sources , str , onProjectLangs ));
89
+ res .addAll (this .format (sources , str , null ));
90
90
}
91
91
return res ;
92
92
}
93
93
94
- public Set <String > format (List <File > sources , String toFormat , boolean onProjectLangs ) {
94
+ public List <String > format (List <File > sources , List < String > toFormat , LanguageMapping languageMapping ) {
95
95
if (sources == null || toFormat == null ) {
96
- return new HashSet <>();
96
+ return new ArrayList <>();
97
+ }
98
+ List <String > res = new ArrayList <>();
99
+ for (String str : toFormat ) {
100
+ res .addAll (this .format (sources , str , languageMapping ));
97
101
}
102
+ return res ;
103
+ }
98
104
99
- List <Language > languages = (onProjectLangs ? projectLanguages : supportedLanguages );
105
+ public Set <String > format (List <File > sources , String toFormat , LanguageMapping languageMapping ) {
106
+ if (sources == null || toFormat == null ) {
107
+ return new HashSet <>();
108
+ }
100
109
101
- return languages .stream ()
102
- .map (lang -> this .replaceLanguageDependentPlaceholders (toFormat , lang ))
110
+ return supportedLanguages .stream ()
111
+ .map (lang -> languageMapping == null
112
+ ? this .replaceLanguageDependentPlaceholders (toFormat , lang )
113
+ : this .replaceLanguageDependentPlaceholders (toFormat , languageMapping , lang ))
103
114
.flatMap (changedToFormat -> sources .stream ()
104
115
.map (source -> this .replaceFileDependentPlaceholders (changedToFormat , source )))
105
116
.collect (Collectors .toSet ());
106
117
}
107
118
119
+ public Set <String > format (List <File > sources , String toFormat ) {
120
+ return this .format (sources , toFormat , null );
121
+ }
122
+
108
123
public String replaceLanguageDependentPlaceholders (String toFormat , Language lang ) {
109
124
if (toFormat == null || lang == null ) {
110
125
throw new NullPointerException ("null args in replaceLanguageDependentPlaceholders()" );
@@ -206,18 +221,17 @@ public String replaceFileDependentPlaceholders(String toFormat, File file) {
206
221
return StringUtils .removeStart (toFormat , Utils .PATH_SEPARATOR );
207
222
}
208
223
209
- public List <String > formatForRegex (List <String > toFormat , boolean onProjectLangs ) {
210
- List <Language > langs = (onProjectLangs ) ? this .projectLanguages : this .supportedLanguages ;
211
- String langIds = langs .stream ().map (Language ::getId ).collect (Collectors .joining ("|" , "(" , ")" ));
212
- String langNames = langs .stream ().map (Language ::getName ).collect (Collectors .joining ("|" , "(" , ")" ));
213
- String langLocales = langs .stream ().map (Language ::getLocale ).collect (Collectors .joining ("|" , "(" , ")" ));
214
- String langLocalesWithUnderscore = langs .stream ().map (Language ::getLocale ).map (s -> s .replace ("-" , "_" ))
224
+ public List <String > formatForRegex (List <String > toFormat ) {
225
+ String langIds = supportedLanguages .stream ().map (Language ::getId ).collect (Collectors .joining ("|" , "(" , ")" ));
226
+ String langNames = supportedLanguages .stream ().map (Language ::getName ).collect (Collectors .joining ("|" , "(" , ")" ));
227
+ String langLocales = supportedLanguages .stream ().map (Language ::getLocale ).collect (Collectors .joining ("|" , "(" , ")" ));
228
+ String langLocalesWithUnderscore = supportedLanguages .stream ().map (Language ::getLocale ).map (s -> s .replace ("-" , "_" ))
215
229
.collect (Collectors .joining ("|" , "(" , ")" ));
216
- String langTwoLettersCodes = langs .stream ().map (Language ::getTwoLettersCode ).collect (Collectors .joining ("|" , "(" , ")" ));
217
- String langThreeLettersCodes = langs .stream ().map (Language ::getThreeLettersCode ).collect (Collectors .joining ("|" , "(" , ")" ));
218
- String langAndroidCodes = langs .stream ().map (Language ::getAndroidCode ).collect (Collectors .joining ("|" , "(" , ")" ));
219
- String langOsxLocales = langs .stream ().map (Language ::getOsxLocale ).collect (Collectors .joining ("|" , "(" , ")" ));
220
- String langOsxCodes = langs .stream ().map (Language ::getOsxCode ).collect (Collectors .joining ("|" , "(" , ")" ));
230
+ String langTwoLettersCodes = supportedLanguages .stream ().map (Language ::getTwoLettersCode ).collect (Collectors .joining ("|" , "(" , ")" ));
231
+ String langThreeLettersCodes = supportedLanguages .stream ().map (Language ::getThreeLettersCode ).collect (Collectors .joining ("|" , "(" , ")" ));
232
+ String langAndroidCodes = supportedLanguages .stream ().map (Language ::getAndroidCode ).collect (Collectors .joining ("|" , "(" , ")" ));
233
+ String langOsxLocales = supportedLanguages .stream ().map (Language ::getOsxLocale ).collect (Collectors .joining ("|" , "(" , ")" ));
234
+ String langOsxCodes = supportedLanguages .stream ().map (Language ::getOsxCode ).collect (Collectors .joining ("|" , "(" , ")" ));
221
235
return toFormat .stream ()
222
236
.map (PlaceholderUtil ::formatSourcePatternForRegex )
223
237
.map (s -> s
0 commit comments