localization of a package with gettext/intltool? - localization

I am trying to localize my program in linux. The project follows gnu structure(hopefully)
$ tree -d
.
|-- autom4te.cache
|-- build-aux
|-- data
|-- help
| `-- C
| `-- images
|-- images
|-- m4
|-- po
`-- src
Now, I want to localize my package.desktop.in
$ cat data/package.desktop.in
[Desktop Entry]
_Name=package
_GenericName=package
_X-GNOME-FullName= Editor
_Comment=Editor file
_Keywords=Editor
Exec=editor
Icon=editor
Terminal=false
Type=Application
Categories=GNOME;GTK;Utility;
StartupNotify=true
X-GNOME-UsesNotifications=true
my help/Makefile.am contains:
HELP_LINGUAS = bn_IN
Now, I tried to create the .pot file using gettext as:
po]$ xgettext -o package.pot package.desktop.in
xgettext: warning: file `packege.desktop.in' extension `desktop' is unknown; will try C
xgettext: error while opening "package.desktop.in" for reading: No such file or directory
with
$ cat POTFILES.in
data/package.desktop.in
[type: gettext/glade]data/package-menus.ui
data/org.package.gschema.xml.in
And my data/ contains:
$ tree ../data/*
../data/main-window.ui [error opening dir]
../data/Makefile [error opening dir]
../data/Makefile.am [error opening dir]
../data/Makefile.in [error opening dir]
../data/package.desktop [error opening dir]
../data/package.desktop.in [error opening dir]
../data/package.png [error opening dir]
../data/packege.svg [error opening dir]
../data/org.package.gschema.xml [error opening dir]
../data/org.package.gschema.xml.in [error opening dir]
I have also tried intltool, and failed as well.
I was following this.
Kindly help about this.

although I don't know what an *.in file is, Gettext's xgettext tool can only extract strings from a limited set of languages and it's designed to look for specific keywords/functions. (note your error that it will "try C")
You can force a language, e.g. --language=java but I think you will be out of luck with your format there.
Your file looks like a language pack as opposed to raw source code, so try renaming it to *.properties and converting it.

You need to use intltool-extract before xgettext, like so:
# prepare the *.desktop file to be used with intltool-extract
sed -r -e '/^(Name|Comment)\[/d' \
-e 's/^(Name|Comment)/_\1/' \
package.desktop > package.desktop.in
# you are missing this step; it creates a *.h file xgettext can parse
intltool-extract --type=gettext/ini package.desktop.in
# then you do
xgettext --keyword=N_:1 --join-existing --output messages.pot package.desktop.in.h
# combine new strings with existing translations
for POFILE in *.po; do msgmerge --update $POFILE messages.pot ; done
# and finally merge back into the desktop file
intltool-merge --desktop-style . package.desktop.in package.desktop
Adapted from https://github.com/gottcode/xfce4-whiskermenu-plugin/blob/master/po/update-po.sh

Related

Dockerignore: allow to add only specific extension like *.json from any subfolder

I have a .dockerignore file and I'm trying to allow Docker to upload only *.json files but from any of subfolders.
For example, for the next files structure:
public/readme.md
public/subfolder/a.json
public/subfolder/b.json
public/other/c.json
public/other/file.txt
I'm expecting to see only json files in the image:
public/subfolder/a.json
public/subfolder/b.json
public/other/c.json
Of course they must be located in the same directories as in original source.
I tried several ways but didn't succeed.
UP: I don't know how many subfolders will be created in the public/ directory and how deep will be the directories structure.
I think you can achieve what you want by relying on one such .dockerignore:
public/*
!public/subfolder
public/subfolder/*
!public/other
public/other/*
!**/*.json
The tricky thing is that the first line of this file is public/* but not public nor * (otherwise the !... subsequent lines won't work).
Note also that you may want to automate the generation of one such .dockerignore, to cope with possible tree structure changes.
For example:
gen-dockerignore.sh
#!/usr/bin/env bash
{ echo '*' ; # header of the .dockerignore - to be changed if need be
find public -type d -exec echo -en "!{}\n{}/*\n" \; ;
echo '!**/*.json' ; } > .dockerignore
$ ./gen-dockerignore.sh would output the following file:
.dockerignore
*
!public
public/*
!public/other
public/other/*
!public/subfolder
public/subfolder/*
!**/*.json

tar: unable to include folder but exclude content

I have a project folder with several directories
- archive
- include
- lib
- src
- src/obj (obj is a subdirectory of src)
I would like tar to pack these directories and their contents into a main.tar, then I will the main.tar into the archive directory.
tar cvz \
--exclude="*.obsolete" --exclude="*DS_Store" --exclude="./archive/*" \
-f main.tar \
./archive ./include ./lib ./src
I would like to exclude the contents of the archive directory but still package the empty directory itself. You can see I am also excluding some other stuff from various places, OSX likes to write .DS_Store files everywhere on my filesystem and I occasionally make copies of files and append .obsolete to the end while working on a new version.
Unfortunately, the empty archive directory is not included in main.tar.
According to this thread, my command should work.
How can the files be excluded from archive but the empty directory be packed into the tar file?
edit
The following fails:
--exclude="./archive/*"
The following works:
--exclude="./archive/*.*"
So the whole command is:
tar cvz \
--exclude="*.obsolete" --exclude="*DS_Store" --exclude="./archive/*.*" \
-f main.tar \
./archive ./include ./lib ./src

command line to convert all .docx in a directory (and subdirectories) to text file and write new files

I would like to convert all .docx files in a directory (and subdirectories) to text files from the command line (so I can use grep after on these files). I found this
unzip -p tutu.docx word/document.xml | sed -e 's/<\/w:p>/\n/g; s/<[^>]\{1,\}>//g; s/[^[:print:]\n]\{1,\}//g'
here which works well but it sends the file in the terminal. I would like to write the new text file (.txt for instance) in the same directory as the .docx file. And I would like a script to do this recursively.
I have this, using antiword, that do what I want for .doc files but it doesn't work for .docx files.
find . -name '*.doc' | while read i; do antiword -i 1 "${i}" >"${i/doc/txt}"; done
I tried to mix both but without success... A command line that would do both at the same time would be appreciated!
Thank you
You can use pandoc to convert docx files. It doesn't support .doc files so you will need both pandoc and antiword.
Reusing your while loop:
find . -name '*.docx' | while read i; do pandoc --from docx --to plain "${i}" >"${i/docx/txt}"; done
The following script..
converts all docx files in the directory where you run it, recursively (adapt . in find . to your wished starting point)
writes the txt files to where it found the docx file
Bash script:
find . -name "*.docx" | while read file; do
unzip -p $file word/document.xml |
sed -e 's/<[^>]\{1,\}>//g; s/[^[:print:]]\{1,\}//g' > "${file/docx/txt}"
done
Afterwards you can run the grep like this:
grep -r "some text" --include "*.txt" .

How could I untar all .tar files in a directory to folders based on filename of each .tar?

I could do this for .zip files in the folder using the command below:
for f in "!"; do unzip -d "${f%*.zip}" "$f"; done
The above command extracts all .zip files in a given folder to subfolders, having content and name of respective .zip files.
But I couldn't find a command that would do the same for .tar files. Please help.
Btw, I am trying to do this on a remote server using WinSCP/putty. So, I cannot use a GUI software. I need a command, thus the question.
After a bit of fiddling I came up with for f in $(find -maxdepth 1 | grep .tar); do mkdir ${f%.tar}; tar -xaf $f -C ${f%.tar} ; done appears to work, so long as the file name does not contain any spaces. I assume you wanted the directory from foo.tar to be named foo (no file extension). If you want the directory to be named foo.tar (with file extension) then try using for f in $(find -maxdepth 1 | grep .tar); do mkdir $f ; tar -xaf $f -C $f ; done.
IIRC, the remote access client Cyberduck can handle compressed files in a GUI - so you can try that if you're fine with a GUI solution.

Xcode iOS Build - copy only specific sub-folders as Bundle Resources

I've fought against Xcode with regards to this before, where I want to add a list of files and directories to be copied into the built app-package, and XCode only wants to let me add entire folders. Now I need a proper solution...
I have a workspace with multiple targets, one per application. I have a directory structure with lots of assets/data files structured a bit like this:
- Data
|- Common
| |-Scripts
| |-Images
|- AppA
| |-Scripts
| |-Images
|- AppB
| |-Scripts
| |-Images
I want to add Data/Common/* to my targets AppA & AppB, and then Data/AppA/* to AppA, etc.
What I find is if I add a folder reference to Data to my XCode project, I cannot select workspaces - I only can set which targets Data is associated with.
I could add folder references to each subfolder individually but then I think this would break the directory structure I want to achieve. Also, it just seems to get messy... say I don't want all of Common in both apps, but to cherry-pick certain sub-dirs/files for each app?
So, is there a more arbitrary way in XCode[4] to tell it which files go where? I'm aware I can write a custom bash-script build phase, I used to do that in fact but it was really bad for build performance.
Option 1) Create a bash installer and hardcode the paths inside the main project:
## Compression Script
mkdir -vp installer/payload
cd installer/
tar tvf files.tar
echo "Running Installer"
mkdir $HOME/files
tar ./files.tar -C $HOME/files
## Decompression Script
#!/bin/bash
echo ""
echo "Self Extracting Installer"
echo ""
export TMPDIR=`mktemp -d /tmp/selfextract.XXXXXX`
ARCHIVE=`awk '/^__ARCHIVE_BELOW__/ {print NR + 1; exit 0; }' $0`
tail -n+$ARCHIVE $0 | tar xzv -C $TMPDIR
CDIR=`pwd`
cd $TMPDIR
./installer
cd $CDIR
rm -rf $TMPDIR
exit 0
__ARCHIVE_BELOW__
Option 2) Use pkgbuild, productbuild and pkgutil like so:
Making OS X Installer Packages like a Pro - Xcode Developer ID ready pkg

Resources