In my project, I included some uncompiled .applescript files I need which get compiled in build phase.
Unfortunately when I try to export for localization, Xcode (8.2) also takes these files into account and crashes with
myfile.applescript cannot be read in UTF-8 encoding
Which is obvious because it's not a textfile. Is there a way to exclude this from creating XLIFF file?
EDIT: creating .strings files with genstrings works though. Just can't export XLIFF
I solved this with removing the applescript temporarily for building XLIFF file.
Related
I am attempting to export XLIFF files for my app. I currently have 2 .strings files one from a module and one in the app itself, and one .stringsdict file.
When I select the project file, and go to editor > Export for localization only the strings from the first file are included (the one from the other module) in the exported XLIFF file.
I was able to figure this out.
Just a simple oversight, needed to link these localization files to my project by tapping on this "Locaolize..." button in the right pain
Situation:
We use XCode exporting/importing tools to generate localizable files for our translators. This was going fine in XCode 8. Since we updated to XCode 9 we see a couple of problems.
Problems:
When exporting a localization via Editor-->Export for localization...-->Development language only, it doesn't include NSLocalizedString() key/values as it should according to this documentation: When you export localizations, Xcode searches your code for the macros and includes the strings files in the exported localization file for translation.
Comments that are added to the Localizable.strings development-language file seem to be non-existent in the export .xliff file.
When importing a translated .xliff file, XCode seems to delete all the comments that are in the file. It gets replaced by "(No Comment)"
Configuration:
XCode 9.0 (9A235)
Dev language: NL
Localized languages: Base, NL, DE, BE, LU
Objective-C & Swift hybrid project
What I've tried:
I have tried looking at XCode 9 documentation or changelog to see what has changed in Localization, though nothing I can find mentions this change
I can get my NSLocalizedString() strings to show up in the export when I first generate the development Localizable.strings file manually, by using the commandline command find ./ -name "*.m" -print0 | xargs -0 xcrun extractLocStrings -o . (I run it a second time for .swift files as my project is a swift/objc hybrid). Then combine the results, which let my strings show up in the export, however without comments, which are needed as guides for translators.
Question:
Is this an XCode 9 bug? Did I miss any documentation or new feature/option for localization exports/imports? Are there workarounds?
This is an older question, but I had this same issue with Xcode 10.
The solution is to simply place the strings files (e.g. InfoPlist.strings) in the same folder as plist.info. Only then are existing translations included in localization exports.
Previously I had them in a dedicated "Localizations" group. While this works for the localization itself (i.e. when running the app), localization exports seem to only include translations from existing strings files that are "near" plist.info.
What fixed both importing and exporting for me was turning off Base Internationalization by unchecking Use Base Internationalization under Project > Info > Localizations. I set all my translations in code, so I don't need it enabled for my .storyboard and .xib files.
Previously, when it was enabled, the "Localizable.strings (Base)" file didn't have anything in it, but Xcode 8 still seemed to work properly by using what was in my "Localizable (English)" file when exporting. For Xcode 9, if I had the source text in Localizable (Base) then exporting worked fine, but I still had problems with importing.
I am using Xcode 9.4.1.
I finally found the reason of the issue.
The issue exists because Xcode never saved files in the encoding it promised.
There are two places to set text encoding, one is "Default text encoding", which including a "convert existing files on save" checkbox.
There is also a file specified "Text Encoding" on each file when you open it. If you don't specify the text encoding on the file, the "Default text encoding" is used.
However, Xcode never saved the file as it promised. For example, if you choose a file specified text encoding, say to "UTF-16", an alert window shows with "Cancel", "Reinterpret", "Convert".
As the alert said, if you chose convert, Xcode would convert the file to the encoding. However, it didn't.
So when you exporting the translations, the file is opened with the encoding it never converted to and ignored.
You can verify that by these steps.
choose a source file.
change it to another text encoding.
in the alert window, choose convert
in Xcode, right click the file and choose Show in Finder.
quit Xcode.
open the file with another text editor that can deal with text encoding, mine is BBEdit.
in BBEdit, choose file -> save as
Now you can see, that the file is not saved in the encoding as it promised.
Solution
The solution is easy. For files that you specified the text encoding, keep it saved in the encoding that it specified. You can do that with other editors, like BBEdit, by save as and choose the right encoding.
For those files that are not specified text encoding. Be sure them are saved as "Default text encoding". If not, change the "Default text encoding" so you won't need to change each file.
After having our app translated in a few languages, we realized that there were a couple .strings files that had been included in the .xliff files that were not needed to be translated, so they could be deleted.
So, I unchecked the localization option for those languages in Xcode and deleted the .string files.
However, now whenever I import a .xliff file it still somehow things in it missing localization for those files we don't want anymore.
Importing will crash Xcode.
Even doing an Export for Localizations will reference those .strings files that are nowhere anymore.
Where in our Xcode project could those files be still referenced? I can't import localizations until I get this fixed.
I've got the same issue, for me it was caused by incorrect paths in xliff itself.
Check the original attribute in files
<file original="..." source-language="en" target-language="cs">
for me it has the path that included the root directory (e.g. "ProjectDir/Resources/..." instead of "Resources/..."). This blocked import.
In your case
I assume you'll have to go through xliff files and find that reference strings that you deleted and remove such blocks (<file original="path/to/deleted.strings">...</file>)
In general
I've written a simple bash script that expects all affected files as arguments and modifies the original attribute in case contains invalid path:
for file in "$#"
do
sed -i '' -E "s#original=\"**ProjectDir**/#original=\"#g" "$file"
done
Replace ProjectDir with whatever your root folder is (or any extra parent folders) and it will be trimmed.
Note that it will edit passed files, so make sure you have a backup.
I'm trying to prepare my app to be passed off to translators for localization, but I'm running into some issues. I added the file "Localizable.strings" to my project, and I have "Use Base Internationalization" checked.
Looking at my app in Xcode, however, I don't see any "Base.lproj" or "en.lproj" or .lproj files for any language, though when I open my app in Finder I can see an "en.lproj" and an "es.lproj" folder.
I'm guessing this may be the reason that the genstrings utility isn't working properly for me. I have many calls in my code like self.navigationItem.title = NSLocalizedString(...), but when I execute genstrings *.swift, nothing changes in Localizable.strings, and I still can't see any .lproj folders.
Xcode doesn't automatically add those files you generated into your build path, you have to manually add them. Also, genstrings generate Localizable.strings file that you can then localize. To generate the lproj files you were talking about, you have to localize your Main.storyboard file.
When building the project for distribution using the Archive build mode, the following error appears. When building in debug or release mode everything works fine. The mentioned directory is empty. The directory permissions are set to full access for the current user. Any ideas?
CopyStringsFile /Users/username/Library/Developer/Xcode/DerivedData/ProjectName-bikjmxotbfpkybhkqwlxysxcibrk/ArchiveIntermediates/ProjectName/InstallationBuildProductsLocation/Applications/ProjectName.app/es.lproj/Localizable.strings ProjectName/Resources/es.lproj/Localizable.strings
cd /Users/username/Coding/proj/game/ProjectName
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/opt/local/bin:/usr/local/git/bin"
builtin-copyStrings --validate --inputencoding utf-8 --outputencoding binary --outdir /Users/username/Library/Developer/Xcode/DerivedData/ProjectName-bikjmxotbfpkybhkqwlxysxcibrk/ArchiveIntermediates/ProjectName/InstallationBuildProductsLocation/Applications/ProjectName.app/es.lproj -- ProjectName/Resources/es.lproj/Localizable.strings
error: failed to remove /Users/username/Library/Developer/Xcode/DerivedData/ProjectName-bikjmxotbfpkybhkqwlxysxcibrk/ArchiveIntermediates/ProjectName/InstallationBuildProductsLocation/Applications/ProjectName.app/es.lproj/Localizable.strings: “Localizable.strings” couldn’t be removed.
This happened to me when I had duplicate references to a folder added to the project. Deleting the duplicate references fixed it.
Ok, i figured it out:
I don't exactly know why Xcode wanted to delete a file that wasn't existent at that location in the first place, but it think it had to do with the project file which was broken for no apparent reason.
The way i fixed it was to just delete all the Localizable.strings files from the project ( i had 6 for different languages each in its own .lproj directory ) and then add them again one by one. –
I also face this type of problem. But what I did is just clean up project "Product -> Clean" and rebuild it fix this problem
I had the same problem ... anyway, these 2 steps definitely solved it:
Make sure the Localizable.strings files are encoded in UTF-16 instead of UTF-8. So if you need to convert them you can do it in XCode by choosing the files and changing the Text Encoding to UTF-16 in the File Inspector
remove the references to the files from your project and re-add them. This should fix the CopyStringsFile error.
I had the same problem and simply cleaning didn't fix it.
I have multiple Build Configurations set up in order to output different apps with different bundle identifiers and a custom script that copies some files. When creating new Build Configurations with new custom files, these files were automatically added to the "Copy Bundle Resources" Build Phase when my script was already taking care of them.
So what I needed to do was simply to remove them from the Copy Bundle Resources list in MyTarget > Build Phases.
Please check this before trying other mentioned steps :-
In my case it was the disk space. I had to free up some space before running it again.
I had same problem: “Localizable.strings” couldn’t be removed. It occurred almost randomly -> when you try to build whole project (after switching git branches or cleaning project) -> Copying Localizable.strings files. I had 4 localisations in my app.
I have tried all mentioned solutions but none of them helped me:
1) project was set up correctly
2) UTF-8 is recommended by Apple itself (https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/LoadingResources/Strings/Strings.html).
Finally I found one more thing. It turned out that my generated (used fastlane poeditor_export plugin) Localizable.strings file had no last line (CR symbol). Added LF (new line feed) symbol to the end of file and build process stopped throwing error.
File was not compliment with POSIX standard (http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206).
Hope this will be helpful to someone ;)
BTW, same issue thread: Localizable.strings error - compiler says file is missing
In my case my .string file was referenced at different location in Xcode sidebar but its actual disk location in computer was different. I moved the file to the referenced location (as same in Xcode) in my computer and it worked well.