From 7ed1539095aba2c1f9c65befeba17fbe7e09bde5 Mon Sep 17 00:00:00 2001 From: abgox Date: Sat, 4 Jan 2025 07:07:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(scripts):=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/auto-update-readme.ps1 | 834 +++++++++++++++++---------------- 1 file changed, 419 insertions(+), 415 deletions(-) diff --git a/scripts/auto-update-readme.ps1 b/scripts/auto-update-readme.ps1 index 72de2e6..83a33d3 100644 --- a/scripts/auto-update-readme.ps1 +++ b/scripts/auto-update-readme.ps1 @@ -1,484 +1,488 @@ -function generate_list { - $content_EN = @() - $content_CN = @() - Get-ChildItem "$PSScriptRoot\..\completions" | ForEach-Object { - $info_EN = @() - $info_CN = @() - $completion = @{} - $json_config = Get-Content "$($_.FullName)/config.json" -Raw -Encoding UTF8 | ConvertFrom-Json -AsHashtable +function Compare-JsonProperty { + param ( + [string]$diffJson, + [string]$baseJson + ) + + # 读取 JSON 文件 + $diffContent = Get-Content -Path $diffJson -Raw | ConvertFrom-Json -AsHashtable + $baseContent = Get-Content -Path $baseJson -Raw | ConvertFrom-Json -AsHashtable + + # 统计 + $count = @{ + totalTips = 0 # 总的 tip 数量 + + diffList = @() # 不同的属性值或类型 + untranslatedList = @() # 未翻译的 + missingList = @() # 缺少的 + extraList = @() # 多余的 + } - $lang_list = Get-ChildItem "$($_.FullName)/language" | ForEach-Object { $_.BaseName } - foreach ($lang in $lang_list) { - $completion.$lang = Get-Content "$($_.FullName)/language/$($lang).json" -Raw -Encoding UTF8 | ConvertFrom-Json -AsHashtable - } - if ("zh-CN" -notin $completion.Keys) { - $completion."zh-CN" = $completion.($lang_list[0]) - } - if ("en-US" -notin $completion.Keys) { - $completion."en-US" = $completion.($lang_list[0]) + function noTranslated() { + param($diffStr, $baseStr) + # XXX: 以中文为例,可以通过判断是否存在中文字符 + # 直接判断是否相等,目前也可用 + return $diffStr -eq $baseStr + } + function _replace { + param ($data, $separator = '') + $data = $data -join $separator + $pattern = '\{\{(.*?(\})*)(?=\}\})\}\}' + $matches = [regex]::Matches($data, $pattern) + foreach ($match in $matches) { + $data = $data.Replace($match.Value, (Invoke-Expression $match.Groups[1].Value) -join $separator ) } - if (!$completion."en-US".info) { $completion."en-US".info = $completion.($lang_list[0]).info } - if (!$completion."zh-CN".info) { $completion."zh-CN".info = $completion.($lang_list[0]).info } + if ($data -match $pattern) { (_replace $data) }else { return $data } + } - # Completion - ## EN - if ($json_config.alias) { - $info_EN += "[$($_.Name)($($json_config.alias))]($($completion."en-US".info.completion_info.url))" - } - else { - $info_EN += "[$($_.Name)]($($completion."en-US".info.completion_info.url))" - } - ## CN - if ($json_config.alias) { - $info_CN += "[$($_.Name)($($json_config.alias))]($($completion."zh-CN".info.completion_info.url))" - } - else { - $info_CN += "[$($_.Name)]($($completion."zh-CN".info.completion_info.url))" - } + function isExist { + param($v) + # XXX: 在 PowerShell 中,对于空数组,以下两种判断都返回空,而非布尔。空又会被当做 false + # @() -eq $null # 返回空,也就是 false + # @() -ne $null # 返回空,也就是 false + # 因此,如果它的类型是一个数组,就应该认为它存在 + return $v -is [array] -or $v -ne $null + } - # Language - function handle_language($lang_list = $lang_list) { - function Compare-JsonProperty { - param ( - [string]$diffJson, - [string]$baseJson - ) - - # 读取 JSON 文件 - $diffContent = Get-Content -Path $diffJson -Raw | ConvertFrom-Json -AsHashtable - $baseContent = Get-Content -Path $baseJson -Raw | ConvertFrom-Json -AsHashtable - - # 统计 - $count = @{ - totalTips = 0 # 总的 tip 数量 - - diffList = @() # 不同的属性值或类型 - untranslatedList = @() # 未翻译的 - missingList = @() # 缺少的 - extraList = @() # 多余的 + # 定义递归函数以遍历 + function traverseArr { + param ( + [array]$diffArr, # 比对 + [array]$baseArr, # 基准 + [string]$pos = '' + ) + for ($i = 0; $i -lt [Math]::Max($baseArr.Count, $diffArr.Count); $i++) { + if (isExist $baseArr[$i]) { + if (!(isExist $diffArr[$i])) { + $count.missingList += @{ + pos = "$pos[$i]" + } } - function noTranslated() { - param($diffStr, $baseStr) - # XXX: 以中文为例,可以通过判断是否存在中文字符 - # 直接判断是否相等,目前也可用 - return $diffStr -eq $baseStr + # name + if (isExist $baseArr[$i].name) { + if (isExist $diffArr[$i].name) { + if ($baseArr[$i].name -ne $diffArr[$i].name) { + $count.diffList += @{ + base = $baseArr[$i].name + diff = $diffArr[$i].name + pos = "$pos[$i].name" + } + } + } + else { + $count.missingList += @{ + pos = "$pos[$i].name" + value = $baseArr[$i].name + } + } } - function _replace { - param ($data, $separator = '') - $data = $data -join $separator - $pattern = '\{\{(.*?(\})*)(?=\}\})\}\}' - $matches = [regex]::Matches($data, $pattern) - foreach ($match in $matches) { - $data = $data.Replace($match.Value, (Invoke-Expression $match.Groups[1].Value) -join $separator ) + else { + if (isExist $diffArr[$i].name) { + $count.extraList += @{ + pos = "$pos[$i].name" + value = $diffArr[$i].name + } } - if ($data -match $pattern) { (_replace $data) }else { return $data } } - function isExist { - param($v) - # XXX: 在 PowerShell 中,对于空数组,以下两种判断都返回空,而非布尔。空又会被当做 false - # @() -eq $null # 返回空,也就是 false - # @() -ne $null # 返回空,也就是 false - # 因此,如果它的类型是一个数组,就应该认为它存在 - return $v -is [array] -or $v -ne $null + # alias + if (isExist $baseArr[$i].alias) { + if (isExist $diffArr[$i].alias) { + if (Compare-Object $baseArr[$i].alias $diffArr[$i].alias -PassThru) { + $count.diffList += @{ + base = $baseArr[$i].alias -join ' ' + diff = $diffArr[$i].alias -join ' ' + pos = "$pos[$i].alias" + } + } + } + else { + $count.missingList += @{ + pos = "$pos[$i].alias" + value = $baseArr[$i].alias -join ' ' + } + } + } + else { + if (isExist $diffArr[$i].alias) { + $count.extraList += @{ + pos = "$pos[$i].alias" + value = $diffArr[$i].alias -join ' ' + } + } } - # 定义递归函数以遍历 - function traverseArr { - param ( - [array]$diffArr, # 比对 - [array]$baseArr, # 基准 - [string]$pos = '' - ) - for ($i = 0; $i -lt [Math]::Max($baseArr.Count, $diffArr.Count); $i++) { - if (isExist $baseArr[$i]) { - if (!(isExist $diffArr[$i])) { - $count.missingList += @{ - pos = "$pos[$i]" - } + # tip + if (isExist $baseArr[$i].tip) { + $count.totalTips++ + if (isExist $diffArr[$i].tip) { + $json = $diffContent + $info = $json.info + $diffStr = _replace $diffArr[$i].tip + + $json = $baseContent + $info = $json.info + $baseStr = _replace $baseArr[$i].tip + if (noTranslated $diffStr $baseStr) { + $count.untranslatedList += @{ + name = $diffArr[$i].name + value = $diffArr[$i].tip + pos = "$pos[$i].tip" } + } + } + else { + $count.missingList += @{ + pos = "$pos[$i].tip" + value = $baseArr[$i].tip + } + } + } + else { + if (isExist $diffArr[$i].tip) { + $count.extraList += @{ + pos = "$pos[$i].tip" + value = $diffArr[$i].tip + } + } + } + } + else { + if (isExist $diffArr[$i]) { + $count.extraList += @{ + pos = "$pos[$i]" + } + } + } - # name - if (isExist $baseArr[$i].name) { - if (isExist $diffArr[$i].name) { - if ($baseArr[$i].name -ne $diffArr[$i].name) { - $count.diffList += @{ - base = $baseArr[$i].name - diff = $diffArr[$i].name - pos = "$pos[$i].name" - } - } - } - else { - $count.missingList += @{ - pos = "$pos[$i].name" - value = $baseArr[$i].name - } - } - } - else { - if (isExist $diffArr[$i].name) { - $count.extraList += @{ - pos = "$pos[$i].name" - value = $diffArr[$i].name - } - } + # next + # options + foreach ($item in @('next', 'options')) { + if (isExist $baseArr[$i].$item) { + if (isExist $diffArr[$i].$item) { + $baseType = $baseArr[$i].$item.GetType().Name + $diffType = $diffArr[$i].$item.GetType().Name + if ($baseType -ne $diffType) { + $count.diffList += @{ + base = "$($baseArr[$i].$item)" + diff = "$($diffArr[$i].$item)" + pos = "$pos[$i].$item" } + } + } + else { + $count.missingList += @{ + pos = "$pos[$i].$item" + } + } + } + else { + if (isExist $diffArr[$i].$item) { + $count.extraList += @{ + pos = "$pos[$i].$item" + } + } + } + if ($baseArr[$i].$item -is [array] -and $diffArr[$i].$item -is [array]) { + traverseArr $diffArr[$i].$item $baseArr[$i].$item "$pos[$i].$item" + } + } + } + } - # alias - if (isExist $baseArr[$i].alias) { - if (isExist $diffArr[$i].alias) { - if (Compare-Object $baseArr[$i].alias $diffArr[$i].alias -PassThru) { - $count.diffList += @{ - base = $baseArr[$i].alias -join ' ' - diff = $diffArr[$i].alias -join ' ' - pos = "$pos[$i].alias" - } - } - } - else { - $count.missingList += @{ - pos = "$pos[$i].alias" - value = $baseArr[$i].alias -join ' ' - } - } - } - else { - if (isExist $diffArr[$i].alias) { - $count.extraList += @{ - pos = "$pos[$i].alias" - value = $diffArr[$i].alias -join ' ' - } - } - } + foreach ($item in @('root', 'options', 'common_options')) { + if ($baseContent.$item.Count) { + if ($diffContent.$item.Count) { + traverseArr $diffContent.$item $baseContent.$item $item + } + else { + $count.missingList += @{ + pos = $item + } + } + } + else { + if ($diffContent.$item.Count) { + $count.extraList += @{ + pos = $item + } + } + } + } - # tip - if (isExist $baseArr[$i].tip) { - $count.totalTips++ - if (isExist $diffArr[$i].tip) { - $json = $diffContent - $info = $json.info - $diffStr = _replace $diffArr[$i].tip - - $json = $baseContent - $info = $json.info - $baseStr = _replace $baseArr[$i].tip - if (noTranslated $diffStr $baseStr) { - $count.untranslatedList += @{ - name = $diffArr[$i].name - value = $diffArr[$i].tip - pos = "$pos[$i].tip" - } - } - } - else { - $count.missingList += @{ - pos = "$pos[$i].tip" - value = $baseArr[$i].tip - } - } - } - else { - if (isExist $diffArr[$i].tip) { - $count.extraList += @{ - pos = "$pos[$i].tip" - value = $diffArr[$i].tip - } + if ($baseContent.config.Count) { + for ($i = 0; $i -lt [Math]::Max($baseContent.config.Count, $diffContent.config.Count); $i++) { + if ($baseContent.config[$i]) { + if (!(isExist $diffContent.config)) { + $count.missingList += @{ + pos = "config" + } + } + + if (!(isExist $diffContent.config[$i])) { + $count.missingList += @{ + pos = "config[$i]" + } + } + + # name + # value + foreach ($item in @('name', 'value')) { + if (isExist $baseContent.config[$i].$item) { + if (isExist $diffContent.config[$i].$item) { + $baseType = $baseContent.config[$i].$item.GetType().Name + $diffType = $diffContent.config[$i].$item.GetType().Name + if (($baseType -ne $diffType) -or ($baseContent.config[$i].$item -ne $diffContent.config[$i].$item)) { + $count.diffList += @{ + base = $baseContent.config[$i].$item + diff = $diffContent.config[$i].$item + pos = "config[$i].$item" } } } else { - if (isExist $diffArr[$i]) { - $count.extraList += @{ - pos = "$pos[$i]" - } + $count.missingList += @{ + pos = "config[$i].$item" + value = $baseContent.config[$i].$item } } - - # next - # options - foreach ($item in @('next', 'options')) { - if (isExist $baseArr[$i].$item) { - if (isExist $diffArr[$i].$item) { - $baseType = $baseArr[$i].$item.GetType().Name - $diffType = $diffArr[$i].$item.GetType().Name - if ($baseType -ne $diffType) { - $count.diffList += @{ - base = "$($baseArr[$i].$item)" - diff = "$($diffArr[$i].$item)" - pos = "$pos[$i].$item" - } - } - } - else { - $count.missingList += @{ - pos = "$pos[$i].$item" - } - } - } - else { - if (isExist $diffArr[$i].$item) { - $count.extraList += @{ - pos = "$pos[$i].$item" - } - } + } + else { + if (isExist $diffContent.config[$i].$item) { + $count.extraList += @{ + pos = "config[$i].$item" + value = $diffContent.config[$i].$item } - if ($baseArr[$i].$item -is [array] -and $diffArr[$i].$item -is [array]) { - traverseArr $diffArr[$i].$item $baseArr[$i].$item "$pos[$i].$item" + } + } + } + # values + if (isExist $baseContent.config[$i].values) { + if (isExist $diffContent.config[$i].values) { + if (Compare-Object $baseContent.config[$i].values $diffContent.config[$i].values -PassThru) { + $count.diffList += @{ + base = $baseContent.config[$i].values -join ' ' + diff = $diffContent.config[$i].values -join ' ' + pos = "config[$i].values" } } } + else { + $count.missingList += @{ + pos = "config[$i].values" + value = $baseContent.config[$i].values -join ' ' + } + } } - - foreach ($item in @('root', 'options', 'common_options')) { - if ($baseContent.$item.Count) { - if ($diffContent.$item.Count) { - traverseArr $diffContent.$item $baseContent.$item $item + else { + if (isExist $diffContent.config[$i].values) { + $count.extraList += @{ + pos = "config[$i].values" + value = $diffContent.config[$i].values -join ' ' } - else { - $count.missingList += @{ - pos = $item + } + } + # tip + if ($baseContent.config[$i].tip) { + $count.totalTips++ + + if (isExist $diffContent.config[$i].tip) { + $json = $diffContent + $info = $json.info + $diffStr = _replace $diffContent.config[$i].tip + + $json = $baseContent + $info = $json.info + $baseStr = _replace $baseContent.config[$i].tip + if (noTranslated $diffStr $baseStr) { + $count.untranslatedList += @{ + name = $diffContent.config[$i].name + value = $diffContent.config[$i].tip + pos = "$pos[$i].tip" } } } else { - if ($diffContent.$item.Count) { - $count.extraList += @{ - pos = $item - } + $count.missingList += @{ + pos = "config[$i].tip" + value = $baseContent.config[$i].tip } } } + else { + if ($diffContent.config[$i].tip) { + $count.extraList += @{ + pos = "config[$i].tip" + value = $diffContent.config[$i].tip + } + } + } + } + else { + if ($diffContent.config[$i]) { + $count.extraList += @{ + pos = "config[$i]" + } + } + } + } + } - if ($baseContent.config.Count) { - for ($i = 0; $i -lt [Math]::Max($baseContent.config.Count, $diffContent.config.Count); $i++) { - if ($baseContent.config[$i]) { - if (!(isExist $diffContent.config)) { - $count.missingList += @{ - pos = "config" - } - } - - if (!(isExist $diffContent.config[$i])) { - $count.missingList += @{ - pos = "config[$i]" - } - } - - # name - # value - foreach ($item in @('name', 'value')) { - if (isExist $baseContent.config[$i].$item) { - if (isExist $diffContent.config[$i].$item) { - $baseType = $baseContent.config[$i].$item.GetType().Name - $diffType = $diffContent.config[$i].$item.GetType().Name - if (($baseType -ne $diffType) -or ($baseContent.config[$i].$item -ne $diffContent.config[$i].$item)) { - $count.diffList += @{ - base = $baseContent.config[$i].$item - diff = $diffContent.config[$i].$item - pos = "config[$i].$item" - } - } - } - else { - $count.missingList += @{ - pos = "config[$i].$item" - value = $baseContent.config[$i].$item - } - } - } - else { - if (isExist $diffContent.config[$i].$item) { - $count.extraList += @{ - pos = "config[$i].$item" - value = $diffContent.config[$i].$item - } - } - } - } - # values - if (isExist $baseContent.config[$i].values) { - if (isExist $diffContent.config[$i].values) { - if (Compare-Object $baseContent.config[$i].values $diffContent.config[$i].values -PassThru) { - $count.diffList += @{ - base = $baseContent.config[$i].values -join ' ' - diff = $diffContent.config[$i].values -join ' ' - pos = "config[$i].values" - } - } - } - else { - $count.missingList += @{ - pos = "config[$i].values" - value = $baseContent.config[$i].values -join ' ' - } - } + if ($baseContent.info) { + function traverseObj { + param($diffObj, $baseObj, $pos) + + $keys = @() + $diffObj.Keys + $baseObj.Keys | Sort-Object -Unique + + foreach ($key in $keys) { + if (isExist $baseObj[$key]) { + if (isExist $diffObj[$key]) { + $baseType = $baseObj[$key].GetType().Name + $diffType = $diffObj[$key].GetType().Name + if ($baseType -ne $diffType) { + $count.diffList += @{ + base = $baseObj[$key] + diff = $diffObj[$key] + pos = "$pos.$key" } - else { - if (isExist $diffContent.config[$i].values) { - $count.extraList += @{ - pos = "config[$i].values" - value = $diffContent.config[$i].values -join ' ' + } + else { + switch ($baseObj[$key]) { + { $_ -is [string] -or $_ -is [array] } { + $diffStr = $diffObj[$key] -join ' ' + $baseStr = $baseObj[$key] -join ' ' + if ($diffStr -match '^https?://.+') { + continue } - } - } - # tip - if ($baseContent.config[$i].tip) { - $count.totalTips++ - - if (isExist $diffContent.config[$i].tip) { - $json = $diffContent - $info = $json.info - $diffStr = _replace $diffContent.config[$i].tip - - $json = $baseContent - $info = $json.info - $baseStr = _replace $baseContent.config[$i].tip if (noTranslated $diffStr $baseStr) { + $count.totalTips++ $count.untranslatedList += @{ - name = $diffContent.config[$i].name - value = $diffContent.config[$i].tip - pos = "$pos[$i].tip" + name = $key + value = $diffObj[$key] + pos = "$pos.$key" } } } - else { - $count.missingList += @{ - pos = "config[$i].tip" - value = $baseContent.config[$i].tip - } - } - } - else { - if ($diffContent.config[$i].tip) { - $count.extraList += @{ - pos = "config[$i].tip" - value = $diffContent.config[$i].tip - } - } - } - } - else { - if ($diffContent.config[$i]) { - $count.extraList += @{ - pos = "config[$i]" - } - } - } - } - } - - if ($baseContent.info) { - function traverseObj { - param($diffObj, $baseObj, $pos) - - $keys = @() + $diffObj.Keys + $baseObj.Keys | Sort-Object -Unique - - foreach ($key in $keys) { - if (isExist $baseObj[$key]) { - if (isExist $diffObj[$key]) { - $baseType = $baseObj[$key].GetType().Name - $diffType = $diffObj[$key].GetType().Name - if ($baseType -ne $diffType) { + { $_ -is [int] -or $_ -is [bool] } { + if ($baseObj[$key] -ne $diffObj[$key]) { $count.diffList += @{ base = $baseObj[$key] diff = $diffObj[$key] pos = "$pos.$key" } } - else { - switch ($baseObj[$key]) { - { $_ -is [string] -or $_ -is [array] } { - $diffStr = $diffObj[$key] -join ' ' - $baseStr = $baseObj[$key] -join ' ' - if ($diffStr -match '^https?://.+') { - continue - } - if (noTranslated $diffStr $baseStr) { - $count.totalTips++ - $count.untranslatedList += @{ - name = $key - value = $diffObj[$key] - pos = "$pos.$key" - } - } - } - { $_ -is [int] -or $_ -is [bool] } { - if ($baseObj[$key] -ne $diffObj[$key]) { - $count.diffList += @{ - base = $baseObj[$key] - diff = $diffObj[$key] - pos = "$pos.$key" - } - } - } - { $_ -is [array] } { - if (Compare-Object $baseObj[$key] $diffObj[$key] -PassThru) { - $count.diffList += @{ - base = $baseObj[$key] -join ' ' - diff = $diffObj[$key] -join ' ' - pos = "$pos.$key" - } - } - } - # 对象 - Default { - traverseObj $diffObj[$key] $baseObj[$key] "$pos.$key" - } - } - } } - else { - $count.missingList += @{ - pos = "$pos.$key" + { $_ -is [array] } { + if (Compare-Object $baseObj[$key] $diffObj[$key] -PassThru) { + $count.diffList += @{ + base = $baseObj[$key] -join ' ' + diff = $diffObj[$key] -join ' ' + pos = "$pos.$key" + } } } - } - else { - if (isExist $diffObj[$key]) { - $count.extraList += @{ - pos = "$pos.$key" - } + # 对象 + Default { + traverseObj $diffObj[$key] $baseObj[$key] "$pos.$key" } } } } - traverseObj $diffContent.info $baseContent.info 'info' - } - - if ($count.totalTips -gt 0) { - $completionRate = 100 - (($count.diffList.Count + $count.untranslatedList.Count + $count.missingList.Count + $count.extraList.Count) / $count.totalTips) * 100 + else { + $count.missingList += @{ + pos = "$pos.$key" + } + } } else { - $completionRate = 100 + if (isExist $diffObj[$key]) { + $count.extraList += @{ + pos = "$pos.$key" + } + } } - $completionRate = [Math]::Max([Math]::Round($completionRate, 2), 0.01) - - return $completionRate } + } + traverseObj $diffContent.info $baseContent.info 'info' + } - function getCompletionRate { - param($lang) - Compare-JsonProperty "$($_.FullName)/language/$($lang).json" "$($_.FullName)/language/$($lang_list[0]).json" - } + if ($count.totalTips -gt 0) { + $completionRate = 100 - (($count.diffList.Count + $count.untranslatedList.Count + $count.missingList.Count + $count.extraList.Count) / $count.totalTips) * 100 + } + else { + $completionRate = 100 + } + $completionRate = [Math]::Max([Math]::Round($completionRate, 2), 0.01) - $lang_info = @("**$($lang_list[0])**") - if ($lang_list.Count -gt 1) { - foreach ($lang in $lang_list[1..($lang_list.Count - 1)]) { - $percentage = getCompletionRate $lang - if ($lang -in $json_config.language) { - $lang_info += "**$($lang)($($percentage)%)**" - } - else { - $lang_info += "**~~$($lang)($($percentage)%)~~**" - } - } + return $completionRate +} + +function handle_language { + param( + [string]$name, + [array]$lang_list = $lang_list + ) + function getCompletionRate { + param($lang) + Compare-JsonProperty "$($_.FullName)/language/$($lang).json" "$($_.FullName)/language/$($lang_list[0]).json" + } + + $lang_info = @("[**$($lang_list[0])**](/completions/$($name)/language/$($lang_list[0]).json)") + if ($lang_list.Count -gt 1) { + foreach ($lang in $lang_list[1..($lang_list.Count - 1)]) { + $percentage = getCompletionRate $lang + if ($lang -in $json_config.language) { + $lang_info += "[**$($lang)($($percentage)%)**](/completions/$($name)/language/$($lang).json)" + } + else { + $lang_info += "[**~~$($lang)($($percentage)%)~~**](/completions/$($name)/language/$($lang).json)" } - return $lang_info } + } + return $lang_info +} + +function generate_list { + $content_EN = @() + $content_CN = @() + Get-ChildItem "$PSScriptRoot\..\completions" | ForEach-Object { + $info_EN = @() + $info_CN = @() + $completion = @{} + $json_config = Get-Content "$($_.FullName)/config.json" -Raw -Encoding UTF8 | ConvertFrom-Json -AsHashtable + + $lang_list = Get-ChildItem "$($_.FullName)/language" | ForEach-Object { $_.BaseName } + foreach ($lang in $lang_list) { + $completion.$lang = Get-Content "$($_.FullName)/language/$($lang).json" -Raw -Encoding UTF8 | ConvertFrom-Json -AsHashtable + } + if ("zh-CN" -notin $completion.Keys) { + $completion."zh-CN" = $completion.($lang_list[0]) + } + if ("en-US" -notin $completion.Keys) { + $completion."en-US" = $completion.($lang_list[0]) + } + if (!$completion."en-US".info) { $completion."en-US".info = $completion.($lang_list[0]).info } + if (!$completion."zh-CN".info) { $completion."zh-CN".info = $completion.($lang_list[0]).info } - $lang_info = handle_language + # Completion + ## EN + if ($json_config.alias) { + $info_EN += "[$($_.Name)($($json_config.alias))]($($completion."en-US".info.completion_info.url))" + } + else { + $info_EN += "[$($_.Name)]($($completion."en-US".info.completion_info.url))" + } + ## CN + if ($json_config.alias) { + $info_CN += "[$($_.Name)($($json_config.alias))]($($completion."zh-CN".info.completion_info.url))" + } + else { + $info_CN += "[$($_.Name)]($($completion."zh-CN".info.completion_info.url))" + } + + # Language + $lang_info = handle_language $_.BaseName $lang_list $info_EN += $lang_info -join '
' $info_CN += $lang_info -join '
'