poedit and xml files - internationalization

How to configure poedit to extract strings from xml file?
I have Zend Framework navigation items in .xml like this:
<entry-i>
<label>Text to translate</label>
<params>
...
<params>
<entry-i>
And I want poedit to read just messages from <label>s.

I have been searching for a solution as well, and I have just gotten it to work!
In Poedit (I have 1.4.2), add a new parser (Edit > Preferences) with the following properties:
Language: XML
List of extensions separated by semicolons (e.g. .cpp;.h): *.xml
Parser command: xgettext --force-po -o %o %C %K %F -L glade
An item in keywords list: -k%k
An item in input files list: %f
Source code charset: --from-code=%c
In your translation project, add label and title to your keyword list and update the catalog.

The above advice to abuse the Glade extractor to parse non-Glade XML files is misguided. It’s never going to work well (case in point: some comments around here). Of course, it was better than nothing back in 2010.
Starting with gettext 0.19.7 (bundled with Poedit since 1.8.7), there’s a better way: there’s now builtin support in gettext for custom XML files via ITS rules.
The best way to extract strings from a custom XML file is to
Add a custom extractor with your extension, specifying standard gettext invocation, without the -L glade bit.
Write ITS rules for your file format.
Put them in the location of other .its and .loc files in Poedit’s installation.

For anyone running into problems with the configuration for Poedit on windows, specifically if you get an error message saying that glade and expat are not available, replace the supplied xgettext.exe with current one from the gnuwin32 project:
http://gnuwin32.sourceforge.net/packages/gettext.htm
You need to download the binaries and the dependencies. However, only the binary xgettext.exe must be extracted and related files (just run it and it will tell you what is missing)

Looks like PoEdit does not support XML yet.
I have created a little php script, to extract the labels to .php file,
which PoEdit does understand.
$xml = simplexml_load_file("../application/configs/navigation.xml")
or die("Error: Cannot open XML file");
echo '<?';
foreach($xml->xpath('//label') as $label){
echo 'echo _("'.$label.'");'. PHP_EOL;
}

It worked great!! I found the problem about "glade not supported" using Poedit 1.4.6 in Windows 7 but I fixed by downloading last gnuwin32 binaries and dependencies as user496209 said. Don't download the complet package because PoEdit comes with its own gettext library, so just donwload binaries and dependencies and replace the requested files into the poedit folder.

Related

Make Geany recognize additional file extensions

My default Geany installation on Debian does not recognize some file types out of the box. How can I add extensions, using the same syntax highlighting as other known extensions for simplicity's sake?
In the current case, I'd like Geany to open all .aspx files with the same highlighting as .html files.
Use inside the menu Tools->Configuration files->filetype_extensions.conf. This will allow you to configure the filetypes based on suffix for your user.
Just add new extensions in /usr/local/share/geany/filetype_extensions.conf
I had trouble accomplishing this without help from here.
Go here to read documentation about this topic.
From the Geany menu, go to:
Tools > Configuration Files > filetype_extensions.conf
Go to this line and un-comment it:
#~ [Extensions]
So that it just reads:
[Extensions]
I was needing to add .mjs as an additional extension for javascript. So, for me, I also uncommented this line:
#~ Javascript=*.js;
And changed it to:
Javascript=*.js;*.mjs;
After this, I saved the file.
Now when I opened files having a .mjs file extension, they automatically have Javascript Syntax Highlighting.
I made some suggestions to improve this expeirience here.

Trouble installing Vim plugins on Mac Lion

I have unsuccessfully been trying to install some plugins for VIM for sometime. I have mostly been following the information in this reference. I've basically just been dropping the plugin files in various directories hoping something works, nothing has yet. I have a .vim directory at the following path:
/Users/{my_user_name}/.vim
I have tried adding my files to the directory above as well as a directory inside it called plugins. Can anyone suggest what I might be doing wrong?
When I enter
:help 'rtp'
I get
Unix: "$HOME/.vim,
$VIM/vimfiles,
$VIMRUNTIME,
$VIM/vimfiles/after,
$HOME/.vim/after"
Amiga: "home:vimfiles,
$VIM/vimfiles,
$VIMRUNTIME,
$VIM/vimfiles/after,
home:vimfiles/after"
PC, OS/2: "$HOME/vimfiles,
$VIM/vimfiles,
$VIMRUNTIME,
$VIM/vimfiles/after,
$HOME/vimfiles/after"
Macintosh: "$VIM:vimfiles,
$VIMRUNTIME,
$VIM:vimfiles:after"
The correct location is in a plugin subdirectory (not the plural plugins):
/Users/{my_user_name}/.vim/plugin/*.vim
You can check your actually used path with
:set rtp?
The trailing ? means query value, don't set. (:help rtp is just the general documentation, not what's actually used.)
The useful :scriptnames command will tell you what actually got sourced.
Note that all these instructions are valid for plain *.vim plugin scripts; some plugins are also distributed as (*.zip, or *.tar.gz) archives, or the Vim-specific Vimball (*.vba, *.vmb), which typically contain the subdirectory structure already.
For an hypothetical single-file plugin:
~/.vim/plugin/plugin.vim
For an hypothetical multi-file plugin:
~/.vim/autoload/plugin.vim
~/.vim/plugin/plugin.vim
~/.vim/doc/plugin.txt
If that hypothetical multi-file plugin comes with documentation, run the following command to add it to the :help index:
:helptags ~/.vim/doc
The :scriptnames shows you a list of sourced scripts.
Also, most plugins have some kind of README that details recommended installation procedures: read it.

Adding a user-defined language in Notepad++

I'm trying to add the syntax plugin for the Go programming language in Notepad++.
There is a repository for such user-defined languages. I downloaded and unzipped the Go files, which contained a README, a userDefinedLang_Go.xml, and go.xml.
I attempted to follow the instructions at the bottom of the page as follows. Since I am using Windows 7 (x64), my Notepad++ directory is "C:\Program Files (x86)\Notepad++".
Having not installed a user defined language before, I didn't have a userDefinedLang.xml file already, so I copied userDefinedLang_Go.xml into the root directory, and renamed it to remove the "_Go", making it userDefinedLang.xml.
I then copied go.xml into C:\Program Files (x86)\Notepad++\plugins\APIs\
This seems to be all of the steps necessary. However, when I open Notepad++, there is no "Go" near "Lang => User Defined", and there is no syntactic coloring on a .go file. Attempting to import via "View => User-Defined Dialogue => import" gives a "fail to import" error.
What am I doing wrong? I'm using a clean installation of Notepad++, which is version 6.1.8.
I had to put my userDefineLang.xml file in my AppData\Roaming folder:
C:\Users\[user]\AppData\Roaming\Notepad++
New install of Notepad++ 6.4.5 on Windows 7 64 bit
Download from Notepad++ site:
http://docs.notepad-plus-plus.org/index.php?title=User_Defined_Language_Files#G
Copy "go.xml" to C:\Program Files (x86)\Notepad++\plugins\APIs.
The default install doesn't have any user-defined languages, so you can do this:
Copy "userDefineLang_Go.xml" to C:\Users\\AppData\Roaming\Notepad++
Remove the "_Go" from the file name, so it's "userDefineLang.xml"
Uncomment the opening and closing "NotepadPlus" tags.
(If you already have a userDefineLang.xml then add the content from the _Go file.)
Restart Notepad++.
I just got it working on my system after some tinkering. Put this at the top of the userDefinedLang.xml file and the go.xml file:
<?xml version="1.0" encoding="Windows-1252" ?>
That should do the trick (after reopening Notepad++).
go.xml should be in the plugins/APIs folder, and userDefinedLang.xml goes in the root of Notepad++ as you said.
Something other answers do not discuss: Some older versions of Notepad++ do not appear to work with any of these answers.
I tried pretty much all the solutions before upgrading Notepad++ to version 6.4.2.
xkcd 979
Tested Notepad++ versions:
5.9 - not working - tested by namey
6.4.2 - working - tested by Elysian Fields
6.6.9 - working - tested by namey
For other versions your mileage may vary.
I share the solution I found for Notepad++ 6.5, because I had the same issue than the previous messages.
If not done, do the install steps explained in go\misc\notepadplus\README (userDefineLang.xml,functionList.xml,APIs).
When you don 't have useDefineLang.xml in Notepad++, create one using the file from go\misc\notepadplus\useDefineLang.xml, but don't forget to add the first line <?xml version="1.0" encoding="Windows-1252" ?>
and uncomment NotepadPlus part to have <NotepadPlus> at the beginning and </NotepadPlus> at the end.
Change in functionList.xml: <association ext=".go" id="go"/> BY <association userDefinedLangName="go" id="go"/>
As I didn't have any userDefineLang.xml file by default in Notepad++, I imported this file using the menu Language → Define your language → *Import.
Then stop/start Notepad++.
Check that Go is in the Language menu at the end of the list.
Open a .go file. If the color doesn't change automatically click on go in /Language menu
All were OK after that for me (indentation, color, autocompletion, etc.).
I added pl/sql language syntax to Notepad++. The syntax /language was on the web. Here's how I got it to work ...
Open the XML file using Notepad and added <?xml version="1.0" encoding="Windows-1252" ?> to the very beginning, as David had suggested. Then save it to userDefinedLang_plsql.xml
Paste the file in the Notepad++ root directory.
I also copied it into C:\Program Files (x86)\Notepad++\plugins\APIs\, and navigated to menu Languages → Userdefined, but it did nothing.
So, I then went to menu Languages → Define your language and selected pl/sql from the drop down, renamed it, and saved it in that dialog window.
The new language then it appeared in the language dialog at the end.
userDefineLang resides in C:\Users\username\AppData\Roaming\Notepad++\userDefineLang.xml.
Make sure your Notepad++ is installed under "C:\Program Files(86)", and not under "C:\npp.#.#.#.bin" folder.
And download from https://notepad-plus-plus.org/download. Or simply google "Download Notepad++".
Check out a sample Scala language userDefineLang.xml file here: https://github.com/nfang/scala-syntax-highlighter
If you don't have any user languages defined before, then after renaming userDefinedLang_Go.xml to userDefinedLang.xml, also edit the text of file by adding the tags <NotepadPlus></NotepadPlus> around the original content.

phpDocumentor on legacy code

Can phpDocumentor be used to generate HTML docs for some legacy code that does not necessarily conform to its standard?
I'd like to generate some preliminary documentation for an old code tree and later on start improving my comments and add the appropriate # tags as I get fluent with phpDocumentor. I've never used this piece of software before and the examples I've found focus on how to write new code that conforms to its syntax and generate HTML file by file with the -f parameter.
I've installed latest phpDocumentor through the PEAR command line installer and tried this little *.bat file on Windows XP:
#echo off
phpdoc ^
--directory "\\server\project\trunk" ^
--target "C:\tests\project-doc"
... but this is all I get:
PHP Version 5.3.5
phpDocumentor version 1.4.3
Parsing configuration file phpDocumentor.ini...
(found in C:\Archivos de programa\PHP\pear\data/PhpDocumentor/)...
done
Maximum memory usage set at 256M after considering php.ini...
using tokenizer Parser
directory: '' not found
I've also tried mapping the UNC path to a drive letter:
#echo off
phpdoc ^
--directory "I:\" ^
--target "C:\tests\project-doc"
... but:
PHP Version 5.3.5
phpDocumentor version 1.4.3
Parsing configuration file phpDocumentor.ini...
(found in C:\Archivos de programa\PHP\pear\data/PhpDocumentor/)...
done
Maximum memory usage set at 256M after considering php.ini...
using tokenizer Parser
a target directory must be specified
try phpdoc -h
This error message is the same if I create "C:\tests\project-doc" before.
What's exactly wrong in my syntax?
phpDocumentor can indeed run against "undocumented" code. It builds its docs based on the code itself, and uses the docblocks as additional info (and additional organization, in the case of #package and #subpackage tags).
I'd suggest starting with phpDocumentor against your existing code, and work towards clearing out the warnings you see in the errors.html file that results -- this file is generated in the top level of your output docs, but there isn't any link to it from the output docs.
Once you have those cleared, you can start running phpDocumentor with the -ue argument (--undocumentedelements), which will add new warnings to errors.html, highlighting (in much greater detail) things that still need to be documented in docblocks.
Now, as for the issue you're having trying to run the program against code on a shared drive, I'm not sure what's wrong there. The script is clearly able to execute PHP and find the phpDocumentor code itself. You might try putting the arguments in the same line, rather than using the ^ as a line-feed escape character, and perhaps remove the quotes around the paths (since no spaces exist in the paths).
I think I've found what the issue is. The parameter parser is very picky and it doesn't like neither UNC paths nor bare root directories. If I replace this:
--directory "I:\"
... with this:
--directory "I:\."
... it finally starts running.
I suppose it's a bug. Their bug tracker doesn't seem to be public so I don't know if it's a known issue.

How to install a masked package in Gentoo 2008?

I searched the net and handbook, but I only managed to learn what is the masked package, and not how to install it. I did find some commands, but they don't seem to work on 2008 (looking at it, it seems those are for earlier versions). I have something like this:
localhost ~ # emerge flamerobin
Calculating dependencies
!!! All ebuilds that could satisfy "dev-db/flamerobin" have been masked.
!!! One of the following masked packages is required to complete your request:
- dev-db/flamerobin-0.8.6 (masked by: ~x86 keyword)
- dev-db/flamerobin-0.8.3 (masked by: ~x86 keyword)
I would like to install version 0.8.6, but don't know how? I found some instructions, but they tell me to edit or write to some files under /etc/portage. However, I don't have /etc/portage on my system:
localhost ~ # ls /etc/portage
ls: cannot access /etc/portage: No such file or directory
There are two different kinds of masks in gentoo. Keyword masks and package masks. A keyword mask means that the package is either not supported (or untested) by your architecture, or still in testing. A package mask means that the package is masked for another reason (and for most users it is not smart to unmask). The solutions are:
Add a line to /etc/portage/package.keywords (Check man portage in the package.keywords section). This is for the keyword problems.
Add a line to /etc/portage/package.unmask for "package.mask" problems (you can also use package.mask for the converse). This is in the same man file, under the section package.unmask. I advise to use versioned atoms here to avoid shooting in your own foot with really broken future versions a couple of months down the line.
These days there's also a more 'automated' solution, called "autounmask". No more file editing needed to unmask!
The great benefit of the package is, it also unmasks / handles keywords of dependencies if needed. It's provided in the package app-portage/autounmask.
/etc/portage/package.keywords and
/etc/portage/package.unmask
can be directories as well nowadays (but autounmask handles single files as well). In those directories, multiple can place multiple "autounmask" files, one file in each dir per "unmask"-package. If you use single files instead of dirs, 'autounmask' will place some kind of header / footer, and this way it becomes easy to remove "unmasks" if wanted.
Simply mkdir /etc/portage and edit as mentioned here: http://gentoo-wiki.com/TIP_Dealing_with_masked_packages#But_you_want_to_install_the_package_anyway...

Resources