Export app for localization not including strings created with NSLocalizedString in Xcode 6 Xliff - xcode

I'm trying to localize my app, and I have the following code:
self.arrayLabels = [NSArray arrayWithObjects:NSLocalizedString(#"This is a test", "this is a test"), NSLocalizedString(#"I want my strings to get added to localizable strings file", "strings comment") , nil];
So, basically, from what I understand, this should be it, I click Editor > Export for Localization and the strings should be there on my XLiff file. But, they aren't.
I have two languages, english and portuguese, both localizable.strings files are empty.
Am I missing something?

I discovered that I had a few errors and that is why I could not export from the menu.
I suspect that the error messages are not being returned.
It turns out that the menu is calling existing command line tools so by a process of elimination you may be able to fix your export.
Here are the steps I took to fix my issues. Hopefully they will help you.
Run the command line equivalent
xcodebuild -exportLocalizations
If you have errors xcodebuild may give file names and line numbers so you should be able to fix the issues.
I had one error that did not have any details.
I then switched to using genstrings as that is what xcodebuild appears to be using in a loop.
find . -name '*.m' | xargs genstrings -o somePath/en.lproj
this gave the same error
To get the file with the problem I ran each file separately in a loop.
for f in `find . -name '*.m'`; do
echo "processing $f ...";
genstrings -o somePath/en.lproj $f
done
That gave me the name of the file that had an issue.
It turned out that genstrings did not like a special character I was trying to print using a unicode character \U000000B2.

For the exported XLIFF to contain your localized strings, a few conditions have to be met:
The keys must be present in your localized strings file. In your case these files are empty. Which will explain the problem.
You must use the keys as string literal with the NSLocalizedString macro. For example:
This is the correct way:
NSLocalizedString("some_key", "")
This will not work:
let key = "some_key"
NSLocalizedString(key, "")

In Xcode, use the Editor-->"Extract for Localization" menu which will generate the .xliff files (one per language selected). The .xliff files are sent to a translation service for translation. Once the .xliff files are updated by the translation service, you need to import it back into the app using Editor-->"Import Localizations". Once this step is done, for each language, you will find a xx.lproj/ folder with the results of the translation.

Related

How to remove a reoccuring word/character and what comes after, from the filenames of multiple files?

I have several folders of video files where, due to the download manager I use, they are all named in the following format "FILENAME.mp4; filename= FILENAME.mp4" All I've been trying to do is to remove everything after (and including) ".mp4; filename". However, I haven't found a way to do this.
I have tried some free software (such as Renamer, Namechanger, Name Munger for Mac, Transnomino) but I failed to do what I need to.
I'm working on Mac OSX 10.13.6.
Any help with this issue would be appreciated.
You can achieve it using Terminal. Go to the folder where you want to rename files using this cd command, for example:
cd ~/Documents/Videos
And run this command to rename all files recursively:
find . -iname "*.mp4;*" | sed -E 's/(\.[^\.]*)(\.mp4)(.*)/mv "\1\2\3" "\1\2"/' | sh
This command will keep only FILENAME.mp4 part from FILENAME.mp4; filename= FILENAME.mp4 file name
I used to extensively use a windows Rename tool called Renamer 6.0, and it had a "pattern rename" facility called "Multi change" that could have handled this.
In the context of that tool it would be asking for a source pattern like %a= %b and a destination pattern (like %b), everything after the = would be stored in %b variable and then renaming the file to just %b would lose everything after the =
See if your preferred rename tool has a similar facility?
If your tool supports regex, then find: .*?=(.*) and replace with $1
I'm also minded that asking this question on https://unix.stackexchange.com/ might elicit some help crafting a shell script that will perform this rename (though also plenty of shell capable people here, one of them may see it - it's just that it's not quite as hardcore programmer-y a question as most).
If you're willing to learn/use java, then that could be another good way to get the problem solved. It would (at a guess) look something like this:
for (final File f : new File("C:\\temp").listFiles()) {
if (f.isFile()) {
string n = f.getName();
if (n.contains("=")) {
f.renameTo(new File(n.substring(n.indexOf("=")+1));
}
}
}

What does slash dot refer to in a file path?

I'm trying to install a grunt template on my computer but I'm having issues. I realized that perhaps something different is happening because of the path given by the Grunt docs, which is
%USERPROFILE%\.grunt-init\
What does that . mean before grunt-init?
I've tried to do the whole import manually but it also isn't working
git clone https://github.com/gruntjs/grunt-init-gruntfile.git "C:\Users\Imray\AppData\Roaming\npm\gru
nt-init\"
I get a message:
fatal: could not create work tree dir 'C:\Users\Imray\AppData\Roaming\npm\.grunt-init"'.: Invalid argument
Does it have to do with this /.? What does it mean?
The \ (that's a backslash, not a slash) is a directory delimiter. The . is simply part of the directory name.
.grunt-init and grunt-init are two distinct names, both perfectly valid.
On Unix-like systems, file and directory names starting with . are hidden by default, which is why you'll often see such names for things like configuration files.
The . is part of a directory name. Filenames can contain . . The \ is a separator between directory names.
Typically, files or directories starting with . are considered "hidden" and/or used for storing metadata. In particular, shell wildcard expansion skips over files that start with ..
For example if you wrote ls -d * then it would not show any files or directories beginning with . (including . and .., the current and parent directories).
Linux hides files and directories whose names begin with dot, unless you use the a (for "all") option when listing directory contents. If this convention is not followed on Windows, your example is probably just a carryover.
It may well be something behind the scenes (later) expects that name to match exactly. While I like things, installers, for example, to just do what I said, I realize that keeping default value is the most tested path.
Directories starting with a dot are invisible by default on xNIX systems. Typically used for configurations files and similar in a users home directory.
\ before " has a special meaning on windows, the error is because windows won't let you create a file containing " as part of its name.

Programming a Filter/Backend to 'Print to PDF' with CUPS from any Mac OS X application

Okay so here is what I want to do. I want to add a print option that prints whatever the user's document is to a PDF and adds some headers before sending it off to a device.
I guess my questions are: how do I add a virtual "printer" driver for the user that will launch the application I've been developing that will make the PDF (or make the PDF and launch my application with references to the newly generated PDF)? How do I interface with CUPS to generate the PDF? I'm not sure I'm being clear, so let me know if more information would be helpful.
I've worked through this printing with CUPS tutorial and seem to get everything set up okay, but the file never seems to appear in the appropriate temporary location. And if anyone is looking for a user-end PDF-printer, this cups-pdf-for-mac-os-x is one that works through the installer, however I have the same issue of no file appearing in the indicated directory when I download the source and follow the instructions in the readme. If anyone can get either of these to work on a mac through the terminal, please let me know step-by-step how you did it.
The way to go is this:
Set up a print queue with any driver you like. But I recommend to use a PostScript driver/PPD. (A PostScript PPD is one which does not contain any *cupsFilter: ... line.):
Initially, use the (educational) CUPS backend named 2dir. That one can be copied from this website: KDE Printing Developer Tools Wiki. Make sure when copying that you get the line endings right (Unix-like).
Commandline to set up the initial queue:
lpadmin \
-p pdfqueue \
-v 2dir:/tmp/pdfqueue \
-E \
-P /path/to/postscript-printer.ppd
The 2dir backend now will write all output to directory /tmp/pdfqueue/ and it will use a uniq name for each job. Each result should for now be a PostScript file. (with none of the modifications you want yet).
Locate the PPD used by this queue in /etc/cups/ppd/ (its name should be pdfqueue.ppd).
Add the following line (best, near the top of the PPD):
*cupsFilter: "application/pdf 0 -" (Make sure the *cupsFilter starts at the very beginning of the line.) This line tells cupsd to auto-setup a filtering chain that produces PDF and then call the last filter named '-' before it sends the file via a backend to a printer. That '-' filter is a special one: it does nothing, it is a passthrough filter.
Re-start the CUPS scheduler:sudo launchctl unload /System/Library/LaunchDaemons/org.cups.cupsd.plist
sudo launchctl load /System/Library/LaunchDaemons/org.cups.cupsd.plist
From now on your pdfqueue will cause each job printed to it to end up as PDF in /tmp/pdfqueue/*.pdf.
Study the 2dir backend script. It's simple Bash, and reasonably well commented.
Modify the 2dir in a way that adds your desired modifications to your PDF before saving on the result in /tmp/pdfqueue/*.pdf...
Update: Looks like I forgot 2 quotes in my originally prescribed *cupsFilter: ... line above. Sorry!
I really wish I could accept two answers because I don't think I could have done this without all of #Kurt Pfeifle 's help for Mac specifics and just understanding printer drivers and locations of files. But here's what I did:
Download the source code from codepoet cups-pdf-for-mac-os-x. (For non-macs, you can look at http://www.cups-pdf.de/) The readme is greatly detailed and if you read all of the instructions carefully, it will work, however I had a little trouble getting all the pieces, so I will outline exactly what I did in the hopes of saving someone else some trouble. For this, the directory with the source code is called "cups-pdfdownloaddir".
Compile cups-pdf.c contained in the src folder as the readme specifies:
gcc -09 -s -lcups -o cups-pdf cups-pdf.c
There may be a warning: ld: warning: option -s is obsolete and being ignored, but this posed no issue for me. Copy the binary into /usr/libexec/cups/backend. You will likely have to the sudo command, which will prompt you for your password. For example:
sudo cp /cups-pdfdownloaddir/src/cups-pdf /usr/libexec/cups/backend
Also, don't forget to change the permissions on this file--it needs root permissions (700) which can be changed with the following after moving cupd-pdf into the backend directory:
sudo chmod 700 /usr/libexec/cups/backend/cups-pdf
Edit the file contained in /cups-pdfdownloaddir/extra/cups-pdf.conf. Under the "PDF Conversion Settings" header, find a line under the GhostScript that reads #GhostScript /usr/bin/gs. I did not uncomment it in case I needed it, but simply added beneath it the line Ghostscript /usr/bin/pstopdf. (There should be no pre-cursor # for any of these modifications)
Find the line under GSCall that reads #GSCall %s -q -dCompatibilityLevel=%s -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -sOutputFile="%s" -dAutoRotatePage\
s=/PageByPage -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -dPDFSETTINGS=/prepress -c .setpdfwrite \
-f %s Again without uncommenting this, under this I added the line GSCall %s %s -o %s %s
Find the line under PDFVer that reads #PDFVer 1.4 and change it to PDFVer, no spaces or following characters.
Now save and exit editing before copying this file to /etc/cups with the following command
sudo cp cups-pdfdownloaddir/extra/cups-pdf.conf /etc/cups
Be careful of editing in a text editor because newlines in UNIX and Mac environments are different and can potentially ruin scripts. You can always use a perl command to remove them, but I'm paranoid and prefer not to deal with it in the first place.
You should now be able to open a program (e.g. Word, Excel, ...) and select File >> Print and find an available printer called CUPS-PDF. Print to this printer, and you should find your pdfs in /var/spool/cups-pdf/yourusername/ by default.
*Also, I figured this might be helpful because it helped me: if something gets screwed up in following these directions and you need to start over/get rid of it, in order to remove the driver you need to (1) remove the cups-pdf backend from /usr/libexec/cups/backend (2) remove the cups-pdf.conf from /etc/cups/ (3) Go into System Preferences >> Print & Fax and delete the CUPS-PDF printer.
This is how I successfully set up a pdf backend/filter for myself, however there are more details, and other information on customization contained in the readme file. Hope this helps someone else!

Path for tags in VIM for multiple projects

I've recently started using ctags on my projects. I currently have the following setup:
root/tags [contains all non-static tags]
root/foo/tags [contains static tags for the foo directory]
root/bar/tags [static]
root/something/else/tags [etc.]
...
I can set tags=./tags,tags,/path/to/root/tags and everything works perfectly.
However, my problem is that I work on several projects at once, so I have, for example, /path/to/root1, /path/to/root2, and /path/to/root3 all at once. I'd rather not manually set the tags each time I open a file; is there any way I can have tags to to the /path/to/rootX based on the file I'm editting? (i.e., if I'm editing /path/to/root3/foo/x.c, use the tags in root3/tags?
In my case, all of my projects share a common parent directory; what I really want is something like:
set tags=./tags,tags,substitute("%:p:h", "\(^\/path\/to\/.*/\).*$", "\1", "")
but I can't seem to get the right vimfu to make it work.
EDIT: I just realized that this won't work; I can't actually write to root*. Instead, I'd like to store my main ctags file in ~/ctags/root*/tags, where there's a 1:1 mapping between the subdirectories of ~/ctags/ and /path/to/ [For those who may be wondering, these are ClearCase UCM dynamic views; neither /view/XXX/ nor /view/XXX/vobs/ is writable]
If what you want is:
set tags=./tags,tags,substitute("%:p:h", "\(^\/path\/to\/.*/\).*$", "\1", "")
Try:
let &tags = './tags,tags,' . substitute(expand("%:p:h"), "\(^\/path\/to\/.*/\).*$", "\1", "")
There's no expansion in a :set command. Also, "%:p:h" won't be expanded automatically, so use expand(). See:
:help :let-option
:help expand()

VIM+Ctags doesn't work in WinXP

Okay guys, you're my only help :)
I have GVim v. 7.3, Exuberant CTags 5.8, omnicppcomplete (0.41) - all latest, to be exact.
I'm trying to generate tags to use in VIM, but it seems to totally ignore data in tags file.
I've used ctags to generate tags file for bada framework - the file seems to be okay, class definitions present etc. I also tried to apply the same command to STL from Visual Studio.
ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language -force=C++ "c:\bada\1.0.0\Include\"
Also, I've mapped generating tags via hotkey.
map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .
Trying to use any of files generated by these commands did not succeed.
The command :tags shows empty tag list, but doesn't give any error, and I have no clue how to fix this.
Yes, seems that vim actually handles spaces in a weird way (Windows only?), however there are workarounds: either use dos 8.3 short names or use a wildcard instead of a space (?), like
set tags=c:\program?files?(x86)\vim\tags
PS: which tag files was successfully loaded could be checked with the
:echo tagfiles()
command
The problem was with path to tags file: c:\Program Files\Vim\bada. The VIM didn't want to parse string with spaces no matter what the slashes/backslashes used.
Reinstalling VIM to c:\VIM solved the problem.

Resources