* improved the locale kit build rules and headers to use a different set of

B_TRANSLATE-macros when running collectcatkeys, simplifying the regex a lot
* added B_TRANSLATE_NOCOLLECT...-macros for the case where a non-literal
  string shall be translated, but not picked up by collectcatkeys


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37746 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe 2010-07-25 22:47:39 +00:00
parent 68018dbe1a
commit ad51686353
4 changed files with 119 additions and 32 deletions

View File

@ -3,7 +3,7 @@
# Extract catalog entries from the sourcefile and put the output textfile in
# target. This output file is then used to create the binary catalog with
# linkcatkeys.
rule ExtractCatalogEntries target : source : signature : regexp
rule ExtractCatalogEntries target : sources : signature : regexp
{
# get compiler and defines for the platform
local headers ;
@ -55,20 +55,21 @@ rule ExtractCatalogEntries target : source : signature : regexp
HAIKU_CATALOG_REGEXP on $(target) = -r $(regexp) ;
}
SEARCH on $(source) += $(SEARCH_SOURCE) ;
SEARCH on $(sources) += $(SEARCH_SOURCE) ;
MakeLocatePlatform $(target) ;
Depends $(target) : $(source) <build>collectcatkeys ;
Depends $(target) : $(sources) <build>collectcatkeys ;
LocalClean clean : $(target).pre ;
ExtractCatalogEntries1 $(target) : <build>collectcatkeys $(source) ;
ExtractCatalogEntries1 $(target) : <build>collectcatkeys $(sources) ;
}
actions ExtractCatalogEntries1
{
$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
cat "$(2[2-])" | $(CC) -E $(CCDEFS) $(HDRS) - > "$(1)".pre
$(2[1]) $(HAIKU_CATALOG_REGEXP) -s $(HAIKU_CATALOG_SIGNATURE) \
-w -o "$(1)" "$(1)".pre
cat "$(2[2-])" \
| $(CC) -E $(CCDEFS) -DB_COLLECTING_CATKEYS $(HDRS) - > "$(1)".pre
$(2[1]) $(HAIKU_CATALOG_REGEXP) -s $(HAIKU_CATALOG_SIGNATURE) \
-w -o "$(1)" "$(1)".pre
}
rule LinkApplicationCatalog target : sources : signature : language

View File

@ -1,5 +1,5 @@
/*
* Copyright 2003-2009, Haiku, Inc.
* Copyright 2003-2010, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _CATALOG_H_
@ -27,6 +27,10 @@ class BCatalog {
const char *comment = NULL);
const char *GetString(uint32 id);
const char *GetNoAutoCollectString(const char *string,
const char *context = NULL, const char *comment = NULL);
const char *GetNoAutoCollectString(uint32 id);
status_t GetData(const char *name, BMessage *msg);
status_t GetData(uint32 id, BMessage *msg);
@ -54,9 +58,12 @@ class BCatalog {
};
#ifndef B_COLLECTING_CATKEYS
#ifndef B_AVOID_TRANSLATION_MACROS
// macros for easy catalog-access, define B_AVOID_TRANSLATION_MACROS if
// you don't want these:
// you don't want these (in which case you need to collect the catalog keys
// manually, as collectcatkeys won't do it for you):
#undef B_TRANSLATE_CONTEXT
// In a single application, several strings (e.g. 'Ok') will be used
@ -76,7 +83,6 @@ class BCatalog {
// Tip: Use a descriptive name of the class implemented in that
// source-file.
// Translation macros which may be used to shorten translation requests:
#undef B_TRANSLATE
#define B_TRANSLATE(str) \
@ -133,8 +139,82 @@ class BCatalog {
#define B_TRANSLATE_MARK_ID(id) \
BCatalogAddOn::MarkForTranslation((id))
// Translation macros which do not let collectcatkeys try to collect the key
// (useful in combination with the marking macros above):
#undef B_TRANSLATE_NOCOLLECT
#define B_TRANSLATE_NOCOLLECT(str) \
B_TRANSLATE(str)
#undef B_TRANSLATE_NOCOLLECT_COMMENT
#define B_TRANSLATE_NOCOLLECT_COMMENT(str, cmt) \
B_TRANSLATE_COMMENT(str, cmt)
#undef B_TRANSLATE_NOCOLLECT_ALL
#define B_TRANSLATE_NOCOLLECT_ALL(str, ctx, cmt) \
B_TRANSLATE_ALL(str, ctx, cmt)
#undef B_TRANSLATE_NOCOLLECT_ID
#define B_TRANSLATE_NOCOLLECT_ID(id) \
B_TRANSLATE_ID(id)
#endif /* B_AVOID_TRANSLATION_MACROS */
#else /* B_COLLECTING_CATKEYS */
// Translation macros used when executing collectcatkeys
#undef B_TRANSLATE_CONTEXT
#undef B_TRANSLATE
#define B_TRANSLATE(str) \
B_CATKEY((str), B_TRANSLATE_CONTEXT)
#undef B_TRANSLATE_COMMENT
#define B_TRANSLATE_COMMENT(str, cmt) \
B_CATKEY((str), B_TRANSLATE_CONTEXT, (cmt))
#undef B_TRANSLATE_ALL
#define B_TRANSLATE_ALL(str, ctx, cmt) \
B_CATKEY((str), (ctx), (cmt))
#undef B_TRANSLATE_ID
#define B_TRANSLATE_ID(id) \
B_CATKEY((id))
#undef B_TRANSLATE_MARK
#define B_TRANSLATE_MARK(str) \
B_CATKEY((str), B_TRANSLATE_CONTEXT)
#undef B_TRANSLATE_MARK_COMMENT
#define B_TRANSLATE_MARK_COMMENT(str, cmt) \
B_CATKEY((str), B_TRANSLATE_CONTEXT, (cmt))
#undef B_TRANSLATE_MARK_ALL
#define B_TRANSLATE_MARK_ALL(str, ctx, cmt) \
B_CATKEY((str), (ctx), (cmt))
#undef B_TRANSLATE_MARK_ID
#define B_TRANSLATE_MARK_ID(id) \
B_CATKEY((id))
#undef B_TRANSLATE_NOCOLLECT
#define B_TRANSLATE_NOCOLLECT(str) \
(void)
#undef B_TRANSLATE_NOCOLLECT_COMMENT
#define B_TRANSLATE_NOCOLLECT_COMMENT(str, cmt) \
(void)
#undef B_TRANSLATE_NOCOLLECT_ALL
#define B_TRANSLATE_NOCOLLECT_ALL(str, ctx, cmt) \
(void)
#undef B_TRANSLATE_NOCOLLECT_ID
#define B_TRANSLATE_NOCOLLECT_ID(id) \
(void)
#endif /* B_COLLECTING_CATKEYS */
/************************************************************************/
// For BCatalog add-on implementations:
@ -254,6 +334,21 @@ BCatalog::GetFingerprint(uint32 *fp)
}
inline const char *
BCatalog::GetNoAutoCollectString(const char *string, const char *context,
const char *comment)
{
return GetString(string, context, comment);
}
inline const char *
BCatalog::GetNoAutoCollectString(uint32 id)
{
return GetString(id);
}
inline status_t
BCatalog::InitCheck() const
{
@ -288,22 +383,16 @@ BCatalogAddOn::Next()
return fNext;
}
// HACK: newline before '::' to avoid this being a false positive for
// collectcatkeys
inline const char *
BCatalogAddOn
::MarkForTranslation(const char *str, const char *ctx,
BCatalogAddOn::MarkForTranslation(const char *str, const char *ctx,
const char *cmt)
{
return str;
}
// HACK: newline before '::' to avoid this being a false positive for
// collectcatkeys
inline int32
BCatalogAddOn
::MarkForTranslation(int32 id)
BCatalogAddOn::MarkForTranslation(int32 id)
{
return id;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2003-2010, Haiku.
* Copyright 2003-2010, Haiku, Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -29,8 +29,8 @@ const char *inputFile = NULL;
BString outputFile;
const char *catalogSig = NULL;
const char *catalogLang = "English";
BString rxString("(be_locale_roster->GetCatalog\\(\\)\\s*->\\s*GetString\\s*"
"|BCatalogAddOn\\s*::\\s*MarkForTranslation\\s*)");
BString rxString("B_CATKEY\\s*");
BString str, ctx, cmt;
@ -99,7 +99,6 @@ fetchStr(const char *&in, BString &str, bool lookForID)
// Strip all whitespace until we find a closing parenthesis, or the
// beginning of another string
// TODO: ignore comments
while (isspace(*in) || *in == ')') {
if (*in == ')') {
if (parLevel == 0)
@ -185,10 +184,10 @@ collectAllCatalogKeys(BString& inputStr)
if (fetchKey(in)) {
if (haveID) {
if (showKeys)
printf("CatKey(%ld)\n", id);
printf("CatKey(%d)\n", id);
res = catalog->SetString(id, "");
if (res != B_OK) {
fprintf(stderr, "couldn't add key %ld - error: %s\n",
fprintf(stderr, "couldn't add key %d - error: %s\n",
id, strerror(res));
exit(-1);
}
@ -302,7 +301,7 @@ main(int argc, char **argv)
if (showSummary) {
int32 count = catalog->CountItems();
if (count)
fprintf(stderr, "%ld key%s found and written to %s\n",
fprintf(stderr, "%d key%s found and written to %s\n",
count, (count==1 ? "": "s"), outputFile.String());
else
fprintf(stderr, "no keys found\n");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2003-2009, Haiku.
* Copyright 2003-2010, Haiku, Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -28,8 +28,7 @@ const char *inputFile = NULL;
BString outputFile;
const char *catalogSig = NULL;
const char *catalogLang = "English";
BString rxString("(be_locale_roster->GetCatalog\\(\\)\\s*->\\s*GetString\\s*"
"|BCatalogAddOn\\s*::\\s*MarkForTranslation\\s*)");
BString rxString("B_CATKEY\\s*");
BString str, ctx, cmt;
@ -96,7 +95,6 @@ fetchStr(const char *&in, BString &str, bool lookForID)
// Strip all whitespace until we find a closing parenthesis, or the
// beginning of another string
// TODO: ignore comments
while (isspace(*in) || *in == ')') {
if (*in == ')') {
if (parLevel == 0)
@ -188,10 +186,10 @@ collectAllCatalogKeys(BString& inputStr)
if (fetchKey(in)) {
if (haveID) {
if (showKeys)
printf("CatKey(%ld)\n", id);
printf("CatKey(%d)\n", id);
res = catalog->SetString(id, "");
if (res != B_OK) {
fprintf(stderr, "Collectcatkeys: couldn't add key %ld - "
fprintf(stderr, "Collectcatkeys: couldn't add key %d - "
"error: %s\n", id, strerror(res));
exit(-1);
}
@ -303,7 +301,7 @@ main(int argc, char **argv)
if (showSummary) {
int32 count = catalog->CountItems();
if (count)
fprintf(stderr, "%ld key%s found and written to %s\n",
fprintf(stderr, "%d key%s found and written to %s\n",
count, (count==1 ? "": "s"), outputFile.String());
else
fprintf(stderr, "no keys found\n");