@@ -209,12 +209,25 @@ const logSection = (
209209}
210210
211211const processLocale = async (
212+ singleLocale : boolean ,
212213 localeFile : string ,
213214 referenceContent : NestedObject ,
214215 fix = false ,
215216) : Promise < SyncStats > => {
216217 const filePath = join ( LOCALES_DIRECTORY , localeFile )
217218 const localeInfo = checkJsonName ( filePath )
219+
220+ // prevent updating wrong locale file:
221+ // - language locale files at countries allowed: e.g. es.json
222+ // - country locale file forbidden: e.g. es-ES.json
223+ // - target locale file forbidden: e.g. es-419.json
224+ if ( fix && localeInfo . mergeLocale && singleLocale ) {
225+ console . error (
226+ `${ COLORS . red } Error: Locale "${ localeInfo . locale } " cannot be fixed, fix the ${ localeInfo . lang } locale instead!${ COLORS . reset } ` ,
227+ )
228+ process . exit ( 1 )
229+ }
230+
218231 const targetContent = await loadJson ( localeInfo )
219232
220233 const stats : SyncStats = {
@@ -226,7 +239,7 @@ const processLocale = async (
226239 const newContent = syncLocaleData ( referenceContent , targetContent , stats , fix )
227240
228241 // Write if there are removals (always) or we are in fix mode
229- if ( stats . extra . length > 0 || fix ) {
242+ if ( ! localeInfo . mergeLocale && ( stats . extra . length > 0 || fix ) ) {
230243 writeFileSync ( filePath , JSON . stringify ( newContent , null , 2 ) + '\n' , 'utf-8' )
231244 }
232245
@@ -246,7 +259,12 @@ const runSingleLocale = async (
246259 process . exit ( 1 )
247260 }
248261
249- const { missing, extra, referenceKeys } = await processLocale ( localeFile , referenceContent , fix )
262+ const { missing, extra, referenceKeys } = await processLocale (
263+ true ,
264+ localeFile ,
265+ referenceContent ,
266+ fix ,
267+ )
250268
251269 console . log (
252270 `${ COLORS . cyan } === Missing keys for ${ localeFile } ${ fix ? ' (with --fix)' : '' } ===${ COLORS . reset } ` ,
@@ -286,7 +304,7 @@ const runAllLocales = async (referenceContent: NestedObject, fix = false): Promi
286304 let totalAdded = 0
287305
288306 for ( const localeFile of localeFiles ) {
289- const stats = await processLocale ( localeFile , referenceContent , fix )
307+ const stats = await processLocale ( false , localeFile , referenceContent , fix )
290308 results . push ( {
291309 file : localeFile ,
292310 ...stats ,
0 commit comments