本文介绍了智能订购Localized.strings文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my Localizable.Strings I try to have all pairs in alphabetical order. Is it possible to reorder them alphabetically my Localizable.strings? Maby using genstring or special bash script?

在这里,我还有其他要求要完成:

应该满足此要求,因为在Localized.strings文件中,我的作者,公司名称和产品名称都放在顶部.

This requirement should be met because in Localized.strings file I have author, company name and product name as a comment on top.

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

I want to keep comments to the translated strings and keep new lines between each translation. This comments are generetad by special genstrings command for iOS developers (e.g. find ./ -name "*.m" -print0 | xargs -0 genstrings -o en.lproj find all NSLocalizedString(@"Param",@"Comment") in my code and generate pairs /* Comment */ /r/n "Param" = "Param"; to file). Comment line before translation is optional and may have only 1 line . For example file:

/* 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";

此问题是我自己的问题的更复杂的变体,您可以在这里找到:对.strings文件进行重新排序

This question is the more sophisticated variant ot my own question that you can find here: Reorder .strings file

推荐答案

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

Think this is what you want
In 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行并仍然打印它们

EDIT

To skip the first 5 lines and still print them

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

EDIT 2

I think this should work on Macs

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

这篇关于智能订购Localized.strings文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 09:26