gpt4 book ai didi

ios - 智能排序 Localized.strings 文件

转载 作者:可可西里 更新时间:2023-11-01 05:40:51 24 4
gpt4 key购买 nike

在我的 Localizable.Strings 中,我尝试按字母顺序排列所有对。我的 Localizable.strings 是否可以按字母顺序对它们重新排序? Maby 使用 genstring 或特殊的 bash 脚本?

这里我有额外的要求要完成:

1。排序应不区分大小写。

2。应复制前 X(例如五)行,而不是排序。

应该满足此要求,因为在 Localized.strings 文件中,我在顶部有作者、公司名称和产品名称作为注释。

3。保留评论

我想保留对已翻译字符串的注释并在每次翻译之间保留新行。此注释由 iOS 开发人员的特殊 genstrings 命令生成(例如 find ./-name "*.m"-print0 | xargs -0 genstrings -o en.lproj find all NSLocalizedString(@ "Param",@"Comment") 在我的代码中生成对 /* Comment *//r/n "Param"= "Param"; 到文件)。翻译前的注释行是可选的,可能只有 1 行。例如文件:

/* This is Billy */
"Billy" = "The smartest guy in the univererse";

/* The Hitchhiker's Guide to the Galaxy */
"42" = "the answer to life the universe and everything";

"Johny" = "Johny";

/* Optional field */
"Anny" = "Anny";

输出应该是:

/* The Hitchhiker's Guide to the Galaxy */
"42" = "the answer to life the universe and everything";

/* Optional field */
"Anny" = "Anny";

/* This is Billy */
"Billy" = "The smartest guy in the univererse";

"Johny" = "Johny";

这个问题是我自己的问题的更复杂的变体,您可以在这里找到:Reorder .strings file

最佳答案

认为这就是你想要的
在 awk 中

awk 'BEGIN{RS="";FS="\n"}
{t=$NF}

match(t,/^"([^"]+)/,a){
key[NR]=tolower(a[1])"\t"++x
b[x]=$0
}

END {
asort(key)
for (i=1; i<=x; i++) {
split(key[i],a,"\t")
print b[a[2]] "\n"
}
}' file

输出

/* The Hitchhiker's Guide to the Galaxy */
"42" = "the answer to life the universe and everything";

/* Optional field */
"Anny" = "Anny";

/* This is Billy */
"Billy" = "The smartest guy in the univererse";

"Johny" = "Johny";

编辑

跳过前 5 行并仍然打印它们

awk 'NR<6{print;next}
NR==6{RS="";FS="\n"}
{t=$NF}

match(t,/^"([^"]+)/,a){
key[NR]=tolower(a[1])"\t"++x
b[x]=$0
}

END {
asort(key)
for (i=1; i<=x; i++) {
split(key[i],a,"\t")
print b[a[2]] "\n"
}
}' file

编辑2

我认为这应该适用于 Mac

awk 'NR<6{print;next}
NR==6{RS="";FS="\n"}
{t=$NF}

split(t,a,"\""){
key[NR]=tolower(a[2])"\t"++x
b[x]=$0
}

END {
asort(key)
for (i=1; i<=x; i++) {
split(key[i],a,"\t")
print b[a[2]] "\n"
}
}' file

关于ios - 智能排序 Localized.strings 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27186763/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com