I have done some more research and found the internal cause of the problem,
but not yet what the clean solution would be.
Debugging the ICU code I found the following:
Calling ResourceBundle resourceBundle("icures/icures", "de", status);
results ICU code to properly locate the icures/icures.dat file. But then
it tries to locate icures/icures/de.dat in the package table of contents.
But the table of contents as generated by the commands in my previous
message (below) contains only icures/de.dat in its TOC.
Looking at the code I found out that it does handle paths differently if
they are absolute or have more than one slash / in it. So I tries the
absolute path as well as ./icures/icures which both worked.
While I got it to work, and while probably intended (hence not a bug), IMHO
this is a bad behavior of the library. If ever I would have tried for some
reason with placing the file in a second level subdirectory it would have
worked fine but would have been luck as well.
Looking further in it I tried using ICU_DATA environment variable to use the
dat file by changing icures/icures in the call above to icures and
setting ICU_DATA =icures. This does also work.
First of all I do not see this double slash/absolute path behavior
documented in the user guide. And second I do really believe that this
loading code requires review in order to get a coherent loading behavior.
Gaston
From: Gaston Gloesener [mailto:gaston.gloesener@...]
Sent: Saturday, August 14, 2010 18:49
To: icu-support@...
Subject: [icu-support] Problems with 1st steps in resource bundle usage from
C++
I am trying to test the resource bundles of ICU for localization. I have
read a lot so far as well as found some examples, but still do not manage to
get it work.
What I have:
Resources source files:
root.txt de.txt fr.txt
Example content:
root.txt:
root {
shot { "shot" }
woods { "woods" }
sentence { "I heard a {0} in the {1}." }
}
de.txt:
de {
shot { "Schu" }
woods { "Wäldern" }
sentence { "In den {1} hörte ich einen {0}." }
}
I compile those into .res files by the following command
#genrb root.txt de.txt fr.txt en.txt en_US.txt
Then
# echo de.res en.res en_US.res fr.res root.res >packagelist.txt
# pkgdata --name icures --mode common -v -T tmp -d . packagelist.txt
BTW, opposed to the examples I saw, I was required to have a tempdir
specified with T else I get an error:
Unable to move dat file (./icures.dat) to target location (./icures.dat).
All these files are in the subdirectory icures/ as seen fomr the test
program, after I read about the changes in processing since V2 of ICU
In C++ I have the following:
UErrorCode status = U_ZERO_ERROR;
ResourceBundle resourceBundle("icures/icures", "de", status);
if(U_FAILURE(status))
{
std::cerr<<"Can't open resource bundle. Error is
"<<u_errorName(status)<<std::endl;
return;
}
Which I have also tries to use with no locale () and always get:
Can't open resource bundle. Error is U_MISSING_RESOURCE_ERROR
I have done many steps in trying to get this to work, but unfortunately with
no success. Looking at the source code suggests that the code is not able to
even find the root.
Any clues would be greatly appreciated :-)
Gaston.
|