scripts/api/util.js
async function mergeMessages(locale, messages) {
  const data_path = path.join(LOCALE_DATA_DIR, `${locale}/api_messages.json`);
  let old_messages = {};
  try {
    old_messages = require(data_path);
  } catch (err) {
    console.log(`creating new messages for locale ${locale}`);
  }
  const merged_messages = { ...old_messages, ...messages };
  const sorted_messages = Object.entries(merged_messages)
    .sort((a, b) => a[0].localeCompare(b[0]))
    .reduce((acc, [key, value]) => {
      acc[key] = value;
      return acc;
    }, {});
  const json = JSON.stringify(sorted_messages, undefined, 2);
  await writeFile(data_path, json);
}
async function mergeMessages(locale, messages) {
  const data_path = path.join(LOCALE_DATA_DIR, `${locale}/api_messages.json`);
  let old_messages = {};
  try {
    old_messages = require(data_path);
  } catch (err) {
    console.log(`creating new messages for locale ${locale}`);
  }
  const merged_messages = { ...old_messages, ...messages };
  const sorted_messages = Object.entries(merged_messages)
    .sort((a, b) => a[0].localeCompare(b[0]))
    .reduce((acc, [key, value]) => {
      acc[key] = value;
      return acc;
    }, {});
  const json = JSON.stringify(sorted_messages, undefined, 2);
  await writeFile(data_path, json);
}
async function mergeMessages ( locale , messages ) { const data_path = path . join ( LOCALE_DATA_DIR , ` ${ locale } ` ) ; let old_messages = { } ; try { old_messages = require ( data_path ) ; } catch ( err ) { console . log ( ` ${ locale } ` ) ; } const merged_messages = { ... old_messages , ... messages } ; const sorted_messages = Object . entries ( merged_messages ) . sort ( ( a , b ) => a [ 0 ] . localeCompare ( b [ 0 ] ) ) . reduce ( ( acc , [ key , value ] ) => { acc [ key ] = value ; return acc ; } , { } ) ; const json = JSON . stringify ( sorted_messages , undefined , 2 ) ; await writeFile ( data_path , json ) ; }
merges the messages into the api_messages.json under the specified locale
while sorting the resulting json object by keys
@param {*} locale
@param {*} messages
merges the messages into the api_messages . json under the specified locale while sorting the resulting json object by keys