我正在写一个AppleScript的来解析的iOS本地化文件(/en.lproj/Localizable.strings),翻译值和输出的翻译(/fr.lproj/Localizable.strings)到磁盘UTF-16(Unicode)编码。如何使用AppleScript创建和编写UTF-16文本文件?
出于某种原因,生成的文件在每个字母之间都有一个额外的空格。在进行了一些挖掘之后,我在“了解AppleScript:脚本综合指南”中找到了问题的原因。
“如果你不小心读了UTF-16文件 为的MacRoman,结果值可以 外观乍一看像一个普通的 字符串,尤其是如果它包含 英文文本,你很快就会发现 那但当您尝试使用 时,出现以下错误: 症状是您的“字符串”中的每个可见字符 在它前面似乎都有一个不可见字符 例如,读取UTF-16编码 包含短语“你好”的文本文件3210 World!“作为一个字符串产生一个字符串 ,比如”H l l l o W o r l d! “,其中每个” “实际上是一个不可见的ASCII 0字符。”
因此,例如,我的英语本地化字符串文件有:
"Yes" = "Yes";
而产生的法语本地化字符串文件:
" Y e s " = " O u i " ;
这是我CREATEFILE方法:
on createFile(fileFolder, fileName)
tell application "Finder"
if (exists file fileName of folder fileFolder) then
set the fileAccess to open for access file fileName of folder fileFolder with write permission
set eof of fileAccess to 0
write ((ASCII character 254) & (ASCII character 255)) to fileAccess starting at 0
--write «data rdatFEFF» to fileAccess starting at 0
close access the fileAccess
else
set the filePath to make new file at fileFolder with properties {name:fileName}
set the fileAccess to open for access file fileName of folder fileFolder with write permission
write ((ASCII character 254) & (ASCII character 255)) to fileAccess starting at 0
--write «data rdatFEFF» to fileAccess starting at 0
close access the fileAccess
end if
return file fileName of folder fileFolder as text
end tell
end createFile
这里是我的WriteFile的方法:
on writeFile(filePath, newLine)
tell application "Finder"
try
set targetFileAccess to open for access file filePath with write permission
write newLine to targetFileAccess as Unicode text starting at eof
close access the targetFileAccess
return true
on error
try
close access file filePath
end try
return false
end try
end tell
end writeFile
任何想法,我做错了吗?
我认为手动翻译这将花费更少的时间比写这个AppleScript甚至不工作。 :') – 2011-02-13 00:49:09
Radek,超过150多个短语需要翻译成10多种语言...... – 2011-02-13 01:02:18