
// 初始化一个空的翻译对象
let translations_material = JsonIO.read('kubejs/assets/translations_material/lang/zh_cn.json') || {}
// 遍历全局材料列表
global.materials.forEach(item => {
    let materialKey = item.material

    // 生成标准的tetra.material键
    let baseKey = `tetra.material.${materialKey.split(':')[1]}`
    let prefixKey = `${baseKey}.prefix`;
    let translation = $I18n.get(Item.of(materialKey).getDescriptionId())

    // 将键值对添加到翻译对象中 - 使用简单的字符串值
    if (!translations_material[baseKey]) {
        if (!$I18n.exists(baseKey) && translation != 'Air' && translation != '空气') {
            if (/[\u4e00-\u9fa5]/.test(translation)) {
                translations_material[baseKey] = translation
            }
        }
    }
    if (!translations_material[prefixKey]) {
        if (!$I18n.exists(prefixKey) && translation != 'Air' && translation != '空气') {
            if (/[\u4e00-\u9fa5]/.test(translation)) {
                translations_material[prefixKey] = translation
            }
        }
    }
})
// 写入翻译文件
// JsonIO.jsjs$write('kubejs/assets/translations_material/lang/zh_cn.json', translations_material);




// 基于tooltip自动生成tooltip_short，前者bar用，后者全息球要用
let translations_tooltipShort = JsonIO.read('kubejs/assets/translations_tooltip_short/lang/zh_cn.json') || {}

// 遍历全局材料列表
global.all_effect.forEach(item => {
    let effectName = item.effect_name
    let group = item.group

    let tooltipKey = "tetra.stats." + effectName + ".tooltip"
    let tooltipShortKey = tooltipKey + "_short"

    let translation = $I18n.get(tooltipKey)
    let translationString = String(translation)

    // console.log("类型: " + typeof translation) // 类型: string
    // console.log("translation: " + translation)

    // console.log("类型: " + typeof translationString) // 类型: string
    // console.log("translationString: " + translationString)

    let result = translationString
        .replace(/%s/g, "n")
        .replace(/%%/g, "%")
        .replace(/Format error: /g, "")

    // 将键值对添加到翻译对象中 - 使用简单的字符串值
    if (!translations_tooltipShort[tooltipKey]) {
        // if (!$I18n.exists(tooltipKey)) {
        if (/[\u4e00-\u9fa5]/.test(translation)) {
            translations_tooltipShort[tooltipShortKey] = result
        }
        // }
    }
})

JsonIO.jsjs$write('kubejs/assets/translations_tooltip_short/lang/zh_cn.json', translations_tooltipShort);




let translations_holoSorter = JsonIO.read('kubejs/assets/translations_holosorter/lang/zh_cn.json') || {}
let itemsEffect = JsonIO.readJson("kubejs/client_scripts/yi/json/material/material_effect.json");
itemsEffect.forEach((c) => {
    let effect_name$1 = c.get("names").getAsString()
    let effect_key = c.get("key").getAsString()
    // let effect_num = c.get("counts").getAsString()

    let effectNameKey = "tetra.stats." + effect_key
    let effectNameKey$1 = effectNameKey + ".sorter"

    let displayName = ""
    let isInGlobal = false

    global.all_effect.forEach(item => {
        let effectName = item.effect_name
        if (effectName != effect_key) return
        isInGlobal = true
        let prefix = "";

        displayName = prefix + (prefix ? " " : "") + "[ " + effect_name$1 + " ]";

        translations_holoSorter[effectNameKey$1] = displayName
    })
    if (isInGlobal != true) {

        displayName = "[ " + effect_name$1 + " ]";

        translations_holoSorter[effectNameKey$1] = displayName
    }
})


// console.log(translations_tooltipShort)
// 写入翻译文件
// JsonIO.jsjs$write('kubejs/assets/translations_holosorter/lang/zh_cn.json', translations_holoSorter);
