How to translate a Django application using Poedit? - django

I run django-admin makemessages -l ro -e html,txt,rml in the application's directory (above the locale directory) to generate the PO files. When I open a PO file with Poedit, e.g. locale/ro/LC_MESSAGES/django.po, I can not see where the message is being referenced. The paths from the catalog look like this:
#: admin.py:12 admin.py:23
so Poedit tries to open locale/ro/LC_MESSAGES/admin.py which of course does not exist.
Update:
find -path '*/locale/ro/LC_MESSAGES/django.po' -exec sed --in-place -r '/^#: / s/([a-zA-Z_./]+):([0-9]+)/..\/..\/..\/\1:\2/g' {} \+
fixes the paths, but I would still like to see this problem solved at its core.
I've also reported this on Django's bug tracker.

See the poedit-users mailing list thread (yes, that was the best place to ask).
Update: ​Poedit handles this case correctly since version 1.5.6.

Related

Using ctags and cscope

I did a ctags -R on my project which is in c++, in the directory /project/ntopng. Now, when I start cscope using cscope -R and search for main.cpp, it opens up. But, when I hit ctrl-] on #include "ntop-includes.h" in main.cpp, the error message is tag not found. The header file is inside a sub-directory in /project/ntopng/include. But, ctags -R is recursive so why is it that I am getting an error? I am using Ubuntu 12.04 with the latest version of ctags and cscope. Thank You.
I have given the below answer for Ubuntu 12.04
1. Open any file with vim
2. type :echo &tags ,It will show what path vim is using for tags file.
If it is not the expected tag file path type:
:set tags=path_to_your_tag_file (ex /project/ntopng/tags)
Remember it is valid for the current session only, Now if permanent changes required there are two options.
For All users (requires root privileges) --
1. cd /etc/vim
2. vim vimrc
3. Go to end and add set tags+=tags;path_to_your_tag_file
For the individual user:
1. cd ~
2. vim .vimrc (This file may not exists in that case newly created)
3. set tags+=tags;path_to_your_tag_file
Let me know if it worked for you.

cscope: How to use cscope to search for a symbol using command line?

All the cscope tutorials I found online talk about how to use the interactive mode of cscope to search for symbols in editors such as vim and emacs. But I think it should be possible to issue a command in terminal to do something like
cscope -d -some_options <my symbol>
And I should be able to see a list of results in stdout, instead of having to enter the ncurse UI and do everything there. I think this is possible because the "only" frontend cbrowser can do things like that in its TclTK UI. But the code unfortunately is quite beyond me.
However, I found no documentation about this capability.
Am I dreaming or is there an undocumented way of doing this?
Thanks!
UPDATE
Some progress: If I make a small project of a few files with sub-dir structure. Then rici's answer works out of the box. With a bigger project (thousands of files with complex folder structure). Even with a cscope.out and cscope.files present at the root of the project folder (also my current working directory), I got nothing from the same command and same symbol. I suspect that there is a scalability issue with the command. I also tried command
cat cscope.files | xargs cscope -d -L1 <symbol> -i
to no avail.
UPDATE
Extremely bizarre! I tried to use some other symbols. Turned out that the particular symbol I was searching for cannot be shown using the command line. But all other symbols I tried worked. And cbrowser has no problem finding that "failed" symbol. Anyways, I was just in bad luck. I'll ask a separate question about this anomaly in command line.
I marked rici's answer as correct.
You are probably looking for this:
cscope -L1<symbol>
You could use -d as well, although if you're modifying the files, it's good for cscope to update it's database.
-L means "execute a single line-oriented command", and the following digit (1 in this case), which could also have been written as a separate option, is the specific command, which the manpage confusingly calls a "field". The "fields" are given by the interactive cscope prompt; I added the digit for convenience. "this" refers to the text which follows the digit; remember that it's a pattern so you don't necessarily have to type the full symbol.
0 Find this C symbol:
1 Find this function definition:
2 Find functions called by this function:
3 Find functions calling this function:
4 Find this text string:
5 Change this text string:
6 Find this egrep pattern:
7 Find this file:
8 Find files #including this file:
You can call cscope with the -R version for recursive searching. For example:
cscope -d -f/path/to/cscope.out -R -L1 some_symbol
(searches for the definition of some_symbol)
cscope -d -f/path/to/cscope.out -R -L3 some_symbol
(shows all locations where some_symbol is called)
You can omit the -f option if cscope.out is located in the current working directory.
Note that the above call yield zero results for an indexed symbol if -R is omitted. Very old cscope versions don't support -R. For example, version 15.8a does support it.
The list of possible values for -L is:
0: Find this C symbol
1: Find this definition
2: Find functions called by this function
3: Find functions calling this function
4: Find this text string
6: Find this egrep pattern
7: Find this file
8: Find files #including this file
9: Find places where this symbol is assigned a value
The -R option can also be used when creating the cscope.out file, e.g.:
cscope -bR

grep through an explicit filelist

Stack,
We have many files in our library that were never used in subsequent projects. We are now at a development phase where we can do some good housekeeping and carefully remove unused library code. I am trying to optimize my grep command, it's current implementation is quite slow.
grep --include=*.cpp --recursive --files-with-matches <library function name> <network path to subsequent projects>
The main reason is that the projects path is expansive and the bulk of the time is spent just navigating the directory tree and applying the file mask. This grep command is called many times on the same set of project files.
Rather than navigating the directory tree every call, I would like to grep to reference a static filelist stored on my local disk.
Something akin to this:
grep --from-filelist=c:\MyProjectFileList.txt
The MyProjectFileList.txt would be:
\\server1\myproject1\main.cpp
\\server1\myproject1\func1.cpp
\\server1\myproject2\main.cpp
\\server1\myproject2\method.cpp
Grep would apply the pattern-expression to contents of each of those files. Grep output would be the fully qualified path of the project file that is uses a specific library function.
Grep commands for specific library functions that return no project files are extraneous and can be deleted.
How do you force grep to scan files from an external filelist stored in a text file?
(Thereby removing directory scanning.)
Try around a little using the 'xargs' command and pipes ("|").
Try the following:
while read line; do echo -e "$line"; done < list_of_files.txt | xargs -0 grep **YOUR_GREP_ARGS_HERE**
or in a Windows environment with Powershell installed try...
Get-Content List_of_files.txt | Foreach-Object {grep $_ GREP_ARGS_HERE}
I googled for windows args and found this:
FOR /F %k in (filelist.txt) DO grep yourgrepargs %k
(but I use linux, no idea if it works)

How to provide data for .po translation files?

After running django-admin.py makemessages -l de in Django to create the translation files, you could use a plain text editor or Poedit to fill them out.
Poedit has the advantage that it provides a specialized UI for entering this data. However I keep getting an error message when I switch between the words:
MyBookmarks/locale/de/LC_MESSAGES/django.po:7: header field
`Project-Id-Version' still has the initial default value
What is this? Has anyone with knowledge of internationalization in Django or general users of po / GNU gettext came across this error message?
Many Thanks,
I guess Django leave the header of the .po file customizable by the user, so is up to you to substitute "PACKAGE VERSION" with something more descriptive like "MY FABULOUS APP v.1.0".
To do that on any relevant file in a given path, you can use this command from the command line and in a *nix environment (or anywhere sed and find are available)
find <YOUR_PATH_HERE> -type f -name '*.po' -exec sed -e s'/PACKAGE VERSION/<YOUR_APP_NAME> <YOUR_APP_VERSION>/g' -i.bak {} \;
the command will replace the aforementioned text in every .po file and will save also an unmodified, backup file of each one.
So, in your case the command will be:
find MyBookmarks/ -type f -name '*.po' -exec sed -e s'/PACKAGE VERSION/MyBookmarks v.1.0/g' -i.bak {} \;
I routinely include this command in my fabfile and it solves the issue using POedit 1.5.x (but should work also on previous versions).
NOTE: You have to do that only once for every .po file. Next time you'll launch a ./manage.py makemessages Django will remember the setting.

script to add files to SVN with filters

My bash scripting is weak. I want to create a script that filters and add files to the svn.
So far i have this
ls | egrep -v "(\.tab\.|\.yy\.|\.o$|\.exe$|~$)"
I tried to output it using exec but couldnt figure out how. Before that I checked if svn add uses regex. I am not sure if it does and i couldnt figure out how to reverse the above without the -v (i tired "[^((\.tab\.|\.yy\.|\.o$|\.exe$|~$))]" but that didnt work as expected (it seems to only ignore .tab. files))
How do i create a script to add files to svn after applying a filter? Would this be the most simple way? -> use ls, grep, put into a bash array then use a foreach with an svn add $element ?
NOTE: This is using linux, i dont think i'll have this running on windows (i couldnt set up bison) so as long as it works on most linux distros i am happy. Ignore the fact the above uses .exe
A number of ways:
Use backticks: svn add ``ls | egrep stuff
Use xargs: ls | egrep stuff | xargs svn add
Use find and xargs: find . -type f -name *.c -print | grep -v '\.svn' | xargs svn add
Obviously, change "stuff" and the "-name *.c" to suit your requirements...
Try using find.
find <pattern> -prune .svn -exec svn add {} \;
The command following exec will be executed for each file and {} will be replaced with the filename at each iteration.
I'm not in front of my linux system so I can't get you a pattern that you need right now but if you read the man, you might get there.
Another solution to this is to add those file extensions and the .svn folder to your SVN ignore pattern.
Armed with a client configured as such, you could then do svn add * and get only what you want into SVN.