gpt4 book ai didi

iOS 可本地化字符串字数统计

转载 作者:行者123 更新时间:2023-11-29 01:07:36 24 4
gpt4 key购买 nike

我需要计算翻译 iOS 应用的成本。价格基于字数。我已经在 Localizable.strings 文件中拥有我需要翻译的所有内容。

是否有工具或命令或其他东西可以用来告诉我这个文件中有多少个单词?这不仅仅是将其粘贴到 Word 中的问题,因为我需要忽略所有键和所有注释。

最佳答案

试试这个 bash 脚本。保存到与 en.lproj 文件夹相同的目录中的文本文件(我将其命名为 counter.sh)。

# Delete the comments
cat en.lproj/Localizable.strings | sed '/^\\\*/ d' | sed '/^\/\/*/ d' > temp

# Delete everything up to and including the equals sign
cat temp | sed s/.*\=// > temp.1

# Delete the remaining quotes and semi-colon
cat temp.1 | sed s/\"// | sed s/\"// | sed s/\;// > temp.2

# Use wc to sount and spit out the number of words
wc -w < temp.2

# Remove the temp files
rm -f temp
rm -f temp.1
rm -f temp.2

在终端中打开该目录。

通过运行chmod +x counter.sh授予脚本可执行权限。

通过输入 ./counter.sh 运行脚本,它应该会输出 Localized.strings 文件中的单词数。

免责声明! - 我的 bash 脚本技能很差!如果您的字符串包含转义的 "或 = 字符,此脚本可能会中断,因此它需要稍微收紧。它也做得很糟糕,但应该做您需要它做的事!

关于iOS 可本地化字符串字数统计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36156304/

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