File tree Expand file tree Collapse file tree
library/src/commonMain/kotlin/project/pipepipe/app/helper Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -125,9 +125,41 @@ object LanguageHelper {
125125 " 简体中文" , // zh-Hans
126126 " 繁體中文" // zh-Hant
127127 )
128+ private val languageAliases = mapOf (
129+ " pt-br" to " pt" ,
130+ " zh-cn" to " zh-Hans" ,
131+ " zh-tw" to " zh-Hant" ,
132+ " zh-hk" to " zh-Hant" ,
133+ " he" to " iw" ,
134+ " in" to " id" ,
135+ " nb-no" to " no" ,
136+ " nb" to " no"
137+ )
138+
128139 fun getLocalizedLanguageName (code : String ): String {
140+ val normalizedCode = code.lowercase()
141+
142+ // 先尝试精确匹配
129143 val index = sharedLanguageValues.indexOfFirst { it.equals(code, ignoreCase = true ) }
130- if (index == - 1 ) return code
131- return sharedLanguageEntries[index]
144+ if (index != - 1 ) return sharedLanguageEntries[index]
145+
146+ // 尝试别名映射
147+ val aliasCode = languageAliases[normalizedCode]
148+ if (aliasCode != null ) {
149+ val aliasIndex = sharedLanguageValues.indexOfFirst { it.equals(aliasCode, ignoreCase = true ) }
150+ if (aliasIndex != - 1 ) return sharedLanguageEntries[aliasIndex]
151+ }
152+
153+ // 尝试主语言代码 fallback
154+ val primaryCode = normalizedCode.split(" -" , " _" ).firstOrNull()
155+ if (primaryCode != null && primaryCode != normalizedCode) {
156+ val fallbackIndex = sharedLanguageValues.indexOfFirst {
157+ it.equals(primaryCode, ignoreCase = true )
158+ }
159+ if (fallbackIndex != - 1 ) return sharedLanguageEntries[fallbackIndex]
160+ }
161+
162+ return code
132163 }
164+
133165}
You can’t perform that action at this time.
0 commit comments