* Build tools : allow to run DoCatalogs with a custom regexp for special cases

* Introduce a system-wide localization catalog used for strings hidden deep in some libraries. Add special API to get it.
 * string_for_size is the first to make use of this system wide catalog. This allows to have a fully localized DriveSetup.
 * As a side effect, tracker also uses it. It now requires liblocale.so.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36175 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adrien Destugues
2010-04-11 23:00:25 +00:00
parent 9113ee2cf7
commit e9024a3be5
8 changed files with 54 additions and 11 deletions
+12 -4
View File
@@ -274,7 +274,7 @@ actions ResAttr1
# 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
rule ExtractCatalogEntries target : source : signature : regexp
{
# get compiler and defines for the platform
local headers ;
@@ -320,6 +320,11 @@ rule ExtractCatalogEntries target : source : signature
CC on $(target) = $(cc) ;
HAIKU_CATALOG_SIGNATURE on $(target) = $(signature) ;
if $(regexp) = "" {
HAIKU_CATALOG_REGEXP on $(target) = ;
} else {
HAIKU_CATALOG_REGEXP on $(target) = -r $(regexp) ;
}
SEARCH on $(source) += $(SEARCH_SOURCE) ;
@@ -333,7 +338,7 @@ actions ExtractCatalogEntries1
{
$(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR)
cat "$(2[2-])" | $(CC) -E $(CCDEFS) $(HDRS) - > "$(1)".pre
$(2[1]) -s $(HAIKU_CATALOG_SIGNATURE) -w -o "$(1)" "$(1)".pre
$(2[1]) $(HAIKU_CATALOG_REGEXP) -s $(HAIKU_CATALOG_SIGNATURE) -w -o "$(1)" "$(1)".pre
}
rule LinkApplicationCatalog target : sources : signature : language
@@ -359,9 +364,10 @@ actions LinkApplicationCatalog1
-s $(HAIKU_CATALOG_SIGNATURE) -o "$(1)"
}
rule DoCatalogs target : signature : sources : sourceLanguage
rule DoCatalogs target : signature : sources : sourceLanguage : regexp
{
# DoCatalogs <target> : <signature> : <sources> [ : <sourceLanguage> ]
# [ : <regexp> ]
#
# Extracts the catkeys from a target's source files, generates the
# default catalog from them, and also generates catalogs for all
@@ -373,12 +379,14 @@ rule DoCatalogs target : signature : sources : sourceLanguage
# sources: List of cpp files where to search keys.
# sourceLanguage Short name of the language of used for the strings in
# the sources. Optional: default is "en".
# regexp The regular expression used to parse the files.
# Optional: default is matching be_catalog->GetString
local generatedCatalog = [ FGristFiles $(sourceLanguage:E=en:S=.catalog) ] ;
# generate catkeys file from sources
ExtractCatalogEntries $(generatedCatalog:S=.catkeys)
: [ FGristFiles $(sources) ] : $(signature) ;
: [ FGristFiles $(sources) ] : $(signature) : $(regexp) ;
# find translations
local translationsDir
+6
View File
@@ -0,0 +1,6 @@
1 english system 1811097932
%3.2f GiB StringForSize %3.2f Gio
%3.2f KiB StringForSize %3.2f Kio
%d bytes StringForSize %d octets
%.2f TiB StringForSize %.2f Tio
%3.2f MiB StringForSize %3.2f Mio
-1
View File
@@ -56,7 +56,6 @@ class BCatalog {
extern BCatalog* be_catalog;
extern BCatalog* be_app_catalog;
#ifndef B_AVOID_TRANSLATION_MACROS
// macros for easy catalog-access, define B_AVOID_TRANSLATION_MACROS if
// you don't want these:
+1
View File
@@ -36,6 +36,7 @@ class BLocaleRoster {
// status_t GetLocaleFor(const char *langCode, const char *countryCode);
status_t GetSystemCatalog(BCatalogAddOn **) const;
status_t GetDefaultCollator(BCollator **) const;
status_t GetDefaultLanguage(BLanguage **) const;
status_t GetDefaultCountry(BCountry **) const;
+7
View File
@@ -35,3 +35,10 @@ SharedLibrary liblocale.so
UnicodeChar.cpp
: be $(TARGET_LIBSTDC++) libicu-common.so libicu-i18n.so
;
DoCatalogs liblocale.so :
system
: ../shared/StringForSize.cpp
:
: '"systemCatalog\\s*->\\s*GetString\\s*"'
;
+10
View File
@@ -414,6 +414,16 @@ BLocaleRoster::~BLocaleRoster()
}
status_t
BLocaleRoster::GetSystemCatalog(BCatalogAddOn **catalog) const
{
if(!catalog)
return B_BAD_VALUE;
*catalog = be_locale_roster->LoadCatalog("system");
return B_OK;
}
status_t
BLocaleRoster::GetDefaultCollator(BCollator **collator) const
{
+17 -5
View File
@@ -7,6 +7,10 @@
#include <stdio.h>
#include <Catalog.h>
#include <Locale.h>
#include <LocaleRoster.h>
namespace BPrivate {
@@ -14,27 +18,35 @@ namespace BPrivate {
const char*
string_for_size(double size, char* string, size_t stringSize)
{
BCatalogAddOn* systemCatalog;
be_locale_roster->GetSystemCatalog(&systemCatalog);
double kib = size / 1024.0;
if (kib < 1.0) {
snprintf(string, stringSize, "%d bytes", (int)size);
snprintf(string, stringSize,
systemCatalog->GetString("%d bytes","StringForSize",""),
(int)size);
return string;
}
double mib = kib / 1024.0;
if (mib < 1.0) {
snprintf(string, stringSize, "%3.2f KiB", kib);
snprintf(string, stringSize,
systemCatalog->GetString("%3.2f KiB","StringForSize",""), kib);
return string;
}
double gib = mib / 1024.0;
if (gib < 1.0) {
snprintf(string, stringSize, "%3.2f MiB", mib);
snprintf(string, stringSize,
systemCatalog->GetString("%3.2f MiB","StringForSize",""), mib);
return string;
}
double tib = gib / 1024.0;
if (tib < 1.0) {
snprintf(string, stringSize, "%3.2f GiB", gib);
snprintf(string, stringSize,
systemCatalog->GetString("%3.2f GiB","StringForSize",""), gib);
return string;
}
snprintf(string, stringSize, "%.2f TiB", tib);
snprintf(string, stringSize,
systemCatalog->GetString("%.2f TiB","StringForSize",""), tib);
return string;
}
+1 -1
View File
@@ -91,7 +91,7 @@ SharedLibrary libtracker.so :
VolumeWindow.cpp
WidgetAttributeText.cpp
: be translation $(vector_icon_libs) $(TARGET_LIBSTDC++) libshared.a
: be translation $(vector_icon_libs) $(TARGET_LIBSTDC++) libshared.a liblocale.so
;