/**
 * 本地化对象的值
 * @param obj
 * @param key
 */
export const localeFormat = (obj, key) => {
  const locale = uni.getLocale()
  const value = obj[key]
  if (value && typeof value === 'string') {
    if (value.includes('~~') && value.includes('**')) {
      const s = value.split('~~')
      if (locale.startsWith('zh')) {
        return s[0]
      } else if (locale.startsWith('ru')) {
        const s2 = s[2].split('**')
        return s2[1]
      } else {
        const s1 = s[1].split('**')
        return s1[1]
      }
    }
  }
  return value
}

/**
 * 递归对象进行本地化处理
 * @param obj
 */
export const localeFormatObj = (obj) => {
  if (Array.isArray(obj)) {
    obj.forEach((item, index) => {
      obj[index] = localeFormatObj(item); // 更新数组元素
    });
  } else if (typeof obj === 'object' && obj !== null) {
    Object.keys(obj).forEach(key => {
      const processedValue = localeFormat(obj, key);
      obj[key] = localeFormatObj(processedValue); // 更新对象属性值
    });
  }
  return obj;
}