From 0a255c0c6ae855ad798a5bb518b0e9efd808a8c2 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sun, 27 Sep 2009 21:19:52 +0000 Subject: [PATCH] Cleanup of the locale kit tools : -Jamrule for collectcatkeys no longer print all the strings, only a message when it can't parse one (happens for TR(variable) basically) -Added fingerprint check in the plaintext catalog ReadFromFile. However, the adler checksum is different each time the catalog is loaded because it relies on the string being iterated always in the same order, but this is not always the case with an HashMap ! Some rethinking is needed, so disabled the check for now so it does not breaks the build -Some try to debug the bluetooth preflet localization. Still buggy, but I wanted to commit all this mess before I break everything up again. -Also sorted the fr.catkeys files to be in the same order as the autogenerated en.catkeys (this is useless but makes them easier to check) and updated their fingerprint even if they are still not checked. -Miscelaneous style fixes, small bugfixes, more error checking and error messages saying where they come from. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33322 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- build/jam/BeOSRules | 4 +-- headers/private/locale/HashMapCatalog.h | 4 +-- src/kits/locale/DefaultCatalog.cpp | 17 ++++++----- src/kits/locale/HashMapCatalog.cpp | 21 ++++++++----- src/preferences/bluetooth/BluetoothMain.cpp | 4 +-- .../bluetooth/BluetoothSettingsView.cpp | 4 +-- src/preferences/bluetooth/fr.catkeys | 6 +--- src/preferences/cpufrequency/fr.catkeys | 8 ++--- src/preferences/locale/fr.catkeys | 15 +++++----- src/tools/locale/PlainTextCatalog.cpp | 30 +++++++++++++++---- src/tools/locale/collectcatkeys.cpp | 7 ++--- 11 files changed, 72 insertions(+), 48 deletions(-) diff --git a/build/jam/BeOSRules b/build/jam/BeOSRules index ad5aaa1e72..abcf6c6b79 100644 --- a/build/jam/BeOSRules +++ b/build/jam/BeOSRules @@ -333,7 +333,7 @@ actions ExtractCatalogEntries1 { $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) cat "$(2[2-])" | $(CC) -E $(CCDEFS) $(HDRS) - > "$(1)".pre - $(2[1]) -s $(LOCALE_KIT_SIGNATURE) -p -o "$(1)" "$(1)".pre + $(2[1]) -s $(LOCALE_KIT_SIGNATURE) -w -o "$(1)" "$(1)".pre } # Link catalog entries from given catkey file into output compiled catalog file. @@ -352,7 +352,7 @@ rule LinkApplicationCatalog target : sources : signature : language actions LinkApplicationCatalog1 { $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) - $(2[1]) "$(2[3-])" -l $(2[2]:B) -v -s $(LOCALE_KIT_SIGNATURE) -o "$(1)" + $(2[1]) "$(2[3-])" -l $(2[2]:B) -v -s $(LOCALE_KIT_SIGNATURE) -o "$(1)" } # General rules to invoke from jamfiles and that do (almost) everything related diff --git a/headers/private/locale/HashMapCatalog.h b/headers/private/locale/HashMapCatalog.h index aa4ee5ffea..127d7451d1 100644 --- a/headers/private/locale/HashMapCatalog.h +++ b/headers/private/locale/HashMapCatalog.h @@ -54,7 +54,7 @@ class CatKey { bool operator== (const CatKey& right) const; bool operator!= (const CatKey& right) const; status_t GetStringParts(BString* str, BString* ctx, BString* cmt) const; - static uint32 HashFun(const char* s, int startvalue=0); + static uint32 HashFun(const char* s, int startvalue = 0); // The hash function is called 3 times, cumulating the 3 strings to // calculate the key uint32 GetHashCode() const { return fHashVal; } @@ -68,7 +68,7 @@ namespace BPrivate { class BHashMapCatalog: public BCatalogAddOn { protected: uint32 ComputeFingerprint() const; - typedef HashMap CatMap; + typedef HashMap CatMap; CatMap fCatMap; public: diff --git a/src/kits/locale/DefaultCatalog.cpp b/src/kits/locale/DefaultCatalog.cpp index 1e4ec2374c..22fb8d8bfb 100644 --- a/src/kits/locale/DefaultCatalog.cpp +++ b/src/kits/locale/DefaultCatalog.cpp @@ -160,34 +160,37 @@ DefaultCatalog::ReadFromFile(const char *path) BFile catalogFile; status_t res = catalogFile.SetTo(path, B_READ_ONLY); if (res != B_OK) { - log_team(LOG_DEBUG, "no catalog at %s", path); + log_team(LOG_DEBUG, "LocaleKit DefaultCatalog: no catalog at %s", path); return B_ENTRY_NOT_FOUND; } fPath = path; - log_team(LOG_DEBUG, "found catalog at %s", path); + log_team(LOG_DEBUG, "LocaleKit DefaultCatalog: found catalog at %s", path); off_t sz = 0; res = catalogFile.GetSize(&sz); if (res != B_OK) { - log_team(LOG_ERR, "couldn't get size for catalog-file %s", path); + log_team(LOG_ERR, "LocaleKit DefaultCatalog: couldn't get size for " + "catalog-file %s", path); return res; } auto_ptr buf(new(std::nothrow) char [sz]); if (buf.get() == NULL) { - log_team(LOG_ERR, "couldn't allocate array of %d chars", sz); + log_team(LOG_ERR, "LocaleKit DefaultCatalog: couldn't allocate array " + "of %d chars", sz); return B_NO_MEMORY; } res = catalogFile.Read(buf.get(), sz); if (res < B_OK) { - log_team(LOG_ERR, "couldn't read from catalog-file %s", path); + log_team(LOG_ERR, "LocaleKit DefaultCatalog: couldn't read from " + "catalog-file %s", path); return res; } if (res < sz) { log_team(LOG_ERR, - "only got %lu instead of %Lu bytes from catalog-file %s", res, sz, - path); + "LocaleKit DefaultCatalog: only got %lu instead of %Lu bytes from " + "catalog-file %s", res, sz, path); return res; } BMemoryIO memIO(buf.get(), sz); diff --git a/src/kits/locale/HashMapCatalog.cpp b/src/kits/locale/HashMapCatalog.cpp index 40445a527d..ff82959546 100644 --- a/src/kits/locale/HashMapCatalog.cpp +++ b/src/kits/locale/HashMapCatalog.cpp @@ -79,21 +79,21 @@ CatKey::operator!= (const CatKey& right) const status_t CatKey::GetStringParts(BString* str, BString* ctx, BString* cmt) const { - if(str) *str = fString; - if(ctx) *ctx = fContext; - if(cmt) *cmt = fComment; + if (str) *str = fString; + if (ctx) *ctx = fContext; + if (cmt) *cmt = fComment; return B_OK; } -size_t CatKey::HashFun(const char* s, int startValue) { +uint32 CatKey::HashFun(const char* s, int startValue) { unsigned long h = startValue; for ( ; *s; ++s) - h = 5*h + *s; + h = 5 * h + *s; // Add 1 to differenciate ("ab","cd","ef") from ("abcd","e","f") - h = 5*h + 1; + h = 5 * h + 1; return size_t(h); } @@ -136,7 +136,11 @@ BHashMapCatalog::GetString(uint32 id) const char * BHashMapCatalog::GetString(const CatKey& key) { - return fCatMap.Get(key); + BString value = fCatMap.Get(key); + if (value.Length() == 0) + return NULL; + else + return value.String(); } @@ -230,7 +234,8 @@ BHashMapCatalog::ComputeFingerprint() const int32 hash; CatMap::Iterator iter = fCatMap.GetIterator(); CatMap::Entry entry; - while(iter.HasNext()) { + while (iter.HasNext()) + { entry = iter.Next(); hash = B_HOST_TO_LENDIAN_INT32(entry.key.fHashVal); adler = adler32(adler, reinterpret_cast(&hash), sizeof(int32)); diff --git a/src/preferences/bluetooth/BluetoothMain.cpp b/src/preferences/bluetooth/BluetoothMain.cpp index e3acf0bffa..bdff3f0e0c 100644 --- a/src/preferences/bluetooth/BluetoothMain.cpp +++ b/src/preferences/bluetooth/BluetoothMain.cpp @@ -30,7 +30,7 @@ void BluetoothApplication::AboutRequested() { - (new BAlert("about", TR("Haiku Bluetooth System, (ARCE)\n\n" + (new BAlert("about", /*TR*/("Haiku Bluetooth System, (ARCE)\n\n" "Created by Oliver Ruiz Dorantes\n\n" "With support of:\n" " - Mika Lindqvist\n" @@ -54,7 +54,7 @@ BluetoothApplication::AboutRequested() " - Fredrik Ekdahl\n" " - Raynald Lesieur\n" " - Andreas Färber\n" - " - Jörg Meyer\n" + " - Joerg Meyer\n" "Testing:\n" " - Petter H. Juliussen\n" " - Adrien Destugues\n\n" diff --git a/src/preferences/bluetooth/BluetoothSettingsView.cpp b/src/preferences/bluetooth/BluetoothSettingsView.cpp index 06c69f8bb5..9c077441b0 100644 --- a/src/preferences/bluetooth/BluetoothSettingsView.cpp +++ b/src/preferences/bluetooth/BluetoothSettingsView.cpp @@ -42,7 +42,7 @@ static const char* kAllLabel = TR_MARK("From all devices"); static const char* kTrustedLabel = TR_MARK("Only from Trusted devices"); static const char* kAlwaysLabel = TR_MARK("Always ask"); -static const char* kDesktopLabel = TR_MARK("Desktop"); +static const char* kDesktopLabel = /*TR_MARK*/("Desktop"); static const char* kServerLabel = TR_MARK("Server"); static const char* kLaptopLabel = TR_MARK("Laptop"); static const char* kHandheldLabel = TR_MARK("Handheld"); @@ -62,7 +62,7 @@ BluetoothSettingsView::BluetoothSettingsView(const char* name) fAverageWeightControl = new BSlider("averageWeightControl", TR("Default Inquiry time:"), new BMessage(kMsgSetAverageWeight), 0, 255, B_HORIZONTAL); - fAverageWeightControl->SetLimitLabels(TR("15 secs"), TR("61 secs")); + fAverageWeightControl->SetLimitLabels(/*TR*/("15 secs"), /*TR*/("61 secs")); fAverageWeightControl->SetHashMarks(B_HASH_MARKS_BOTTOM); fAverageWeightControl->SetHashMarkCount(255 / 15); fAverageWeightControl->SetEnabled(true); diff --git a/src/preferences/bluetooth/fr.catkeys b/src/preferences/bluetooth/fr.catkeys index 3ed3470572..c6a992601d 100644 --- a/src/preferences/bluetooth/fr.catkeys +++ b/src/preferences/bluetooth/fr.catkeys @@ -1,4 +1,4 @@ -1 french x-vnd.Haiku-BluetoothPrefs 3058329015 +1 french x-vnd.Haiku-BluetoothPrefs 4182662743 Handheld Settings view Appareil de poche Only from Trusted devices Settings view Seulement les appareils de confiance Refresh LocalDevicesxE2x80xA6 Window Rafraîchir LocalDevicexE2x80xA6 @@ -20,16 +20,13 @@ Server Window Serveur Scanning completed. Inquiry panel Recherche complète. Start Bluetooth ServicesxE2x80xA6 Window Démarrer les services bluetoothxE2x80xA6 Remove Remote devices Enlever -15 secs Settings view 15 secs Policy... Settings view Attitude... -61 secs Settings view 61 secs AddxE2x80xA6 Remote devices AjouterxE2x80xA6 Identify us as... Settings view S'identifier comme... Remaining Inquiry panel Restant Pick LocalDevice... Settings view Choisir LocalDevice... Defaults Window Défauts Inquiry Inquiry panel Requête -Desktop Settings view Bureau Revert Window Défaire AboutxE2x80xA6 Window À proposxE2x80xA6 Remote Devices ListxE2x80xA6 Window Liste d'appareils distantsxE2x80xA6 @@ -45,7 +42,6 @@ Settings Window Param Check that the bluetooth capabilities of your remote device are activated. Press Inquiry to start scanning. The needed time for the retrieval of the names is unknown, although should not take more than 3 seconds per device. Afterwards you will be able to add them to your main list, where you will be able to pair with them Inquiry panel Vérifiez que les fonctionnalités bluetooth de votre appareil distant sont activées. Appuyez sur "Requête" pour lancer la recherche. Le temps nécessaire pour récupérer les noms n'est pas connu, mais ça ne devrait pas prendre plus de 3 secondes par appareil. Ensuite vous pourrez les ajouter à la liste principale, où vous pourrez vous associer avec eux. Scanning progress Inquiry panel Avancée de la recherche Always ask Settings view Toujours demander -Haiku Bluetooth System, (ARCE)\n\nCreated by Oliver Ruiz Dorantes\n\nWith support of:\n\t- Mika Lindqvist\n\t- Maksym Yevmenkin\n\nThanks to the individuals who helped...\n\nShipping/donating hardware:\n\t- Henry Jair Abril Florez(el Colombian)\n\t\t & Stefanie Bartolich\n\t- Edwin Erik Amsler\n\t- Dennis d'Entremont\n\t- Luroh\n\t- Pieter Panman\n\nEconomically:\n\t- Karl vom Dorff, Andrea Bernardi (OSDrawer),\n\t- Matt M, Doug F, Hubert H,\n\t- Sebastian B, Andrew M, Jared E,\n\t- Frederik H, Tom S, Ferry B,\n\t- Greg G, David F, Richard S, Martin W:\n\nWith patches:\n\t- Michael Weirauch\n\t- Fredrik Ekdahl\n\t- Raynald Lesieur\n\t- Andreas Färber\n\t- Jörg Meyer\nTesting:\n\t- Petter H. Juliussen\n\t- Adrien Destugues\n\nWho gave me all the knowledge:\n\t- the yellowTAB team main Système bluetooth Haiku, (ARCE)\n\nCréé par Oliver Ruiz Dorantes\n\nAvec l'aide de :\n\t- Mika Lindqvist\n\t- Maksym Yevmenkin\n\nMerci à tous ceux qui ont aidé...\n\nEnvoi.don de matériel :\n\t- Henry Jair Abril Florez(el Colombian)\n\t\t & Stefanie Bartolich\n\t- Edwin Erik Amsler\n\t- Dennis d'Entremont\n\t- Luroh\n\t- Pieter Panman\n\nÉconomiquement:\n\t- Karl vom Dorff, Andrea Bernardi (OSDrawer),\n\t- Matt M, Doug F, Hubert H,\n\t- Sebastian B, Andrew M, Jared E,\n\t- Frederik H, Tom S, Ferry B,\n\t- Greg G, David F, Richard S, Martin W:\n\nAvec des patches:\n\t- Michael Weirauch\n\t- Fredrik Ekdahl\n\t- Raynald Lesieur\n\t- Andreas Färber\n\t- Jörg Meyer\nTesting:\n\t- Petter H. Juliussen\n\t- Adrien Destugues\n\nQui m'ont tout appris:\n\t- l'équipe yellowTAB Retrieving names... Inquiry panel Récupération des noms... Help Window Aide Ok main Ok diff --git a/src/preferences/cpufrequency/fr.catkeys b/src/preferences/cpufrequency/fr.catkeys index 56dea2fc2c..57b2c82b7c 100644 --- a/src/preferences/cpufrequency/fr.catkeys +++ b/src/preferences/cpufrequency/fr.catkeys @@ -1,7 +1,8 @@ -1 french x-vnd.Haiku-CPUFrequencyPref 1947607562 +1 french x-vnd.Haiku-CPUFrequencyPref 2148935007 Ok Status view Ok -Integration Time [ms] CPU Frequency View Temps d'intégration [ms] +Integration Time [ms] CPU Frequency View Temps d'intégration [ms] High Performance Status view Haute performance +Defaults Pref Window Défaire CPU Frequency Status View CPU Frequency View État de la fréquence du processeur Dynamic Performance Status view Performance dynamique Step up by CPU usage: Color Step View Accélération par utilisation processeur: @@ -11,8 +12,7 @@ Open Speedstep PreferencesxE2x80xA6 Status view Préférences speedstepxE2x80xA Launching the CPU Frequency preflet failed.\n\nError: Status view Échec de lancement des préférences de fréquence du processeur.\n\nErreur: Install Replicant into Deskbar CPU Frequency View Installer le réplicant dans la Deskbar Low Energy Status view Basse consommation +Revert Pref Window Défaire Dynamic Stepping CPU Frequency View Accélération dynamique CPU Frequency\n\twritten by Clemens Zeidler\n\tCopyright 2009, Haiku, Inc.\n Status view Fréquence du processeur\n\técrit par Clemens Zeidler\n\tCopyright 2009, Haiku, Inc.\n CPU Frequency Main window Fréquence du processeur -Defaults Pref Window Défaire -Revert Pref Window Défaire diff --git a/src/preferences/locale/fr.catkeys b/src/preferences/locale/fr.catkeys index d8da8c2a58..6668e23b34 100644 --- a/src/preferences/locale/fr.catkeys +++ b/src/preferences/locale/fr.catkeys @@ -1,8 +1,4 @@ -1 fr x-vnd.Haiku-Locale 2841580836 -Revert Locale Preflet Window Défaire -Country Locale Preflet Window Pays -Language Locale Preflet Window Langage -Preferred languages Locale Preflet Window Langues préférées +1 french x-vnd.Haiku-Locale 1616861198 day of week (short name) TimeFormatSettings jour de la semaine (abrégé) Available languages Locale Preflet Window Langues disponibles Decimal separator TimeFormatSettings Séparateur décimal @@ -10,14 +6,16 @@ Separator: TimeFormatSettings Separateur: Year (4 digits) TimeFormatSettings Année (4 chiffres) After TimeFormatSettings Après Long format: TimeFormatSettings Format long: +Before TimeFormatSettings Avant Currency TimeFormatSettings Avant Year TimeFormatSettings Année Short format: TimeFormatSettings Format court: Currency symbol: TimeFormatSettings Symbole monétaire: -Example: TimeFormatSettings Exemple: Space TimeFormatSettings Espace +Language Locale Preflet Window Langage Thousand separator TimeFormatSettings Séparateur de milliers Year (2 digits) TimeFormatSettings Année (2 chiffres) +Preferred languages Locale Preflet Window Langues préférées Symbol position TimeFormatSettings Position du symbole month number TimeFormatSettings numéro du mois month number (2 digits) TimeFormatSettings numéro du mois (2 chiffres) @@ -28,9 +26,11 @@ Negative marker: TimeFormatSettings Marqueur de nombre négatifs: Defaults Locale Preflet Window Défauts Locale\n\twritten by Axel Dörfler\n\tCopyright 2005, Haiku.\n\n Locale Preflet Locale\n\técrit par Axel Dörfler\n\tCopyright 2009, Haiku.\n\n Separator TimeFormatSettings Separateur -Negative marker TimeFormatSettings Marqueur de nombres négatifs +Country Locale Preflet Window Pays +Revert Locale Preflet Window Défaire day in month TimeFormatSettings jour du mois day of week in month TimeFormatSettings jour de la semaine dans le mois +Negative marker TimeFormatSettings Marqueur de nombres négatifs Ok Locale Preflet Window Ok Time TimeFormatSettings Heure Date TimeFormatSettings Date @@ -39,6 +39,7 @@ day of week TimeFormatSettings jour de la semaine None TimeFormatSettings Aucun day in month (2 digits) TimeFormatSettings jour du mois (2 chiffres) Clock TimeFormatSettings Horloge +Example: TimeFormatSettings Exemple: day of week (name) TimeFormatSettings jour de la semaine (nom) month name TimeFormatSettings nom du mois Day TimeFormatSettings Jour diff --git a/src/tools/locale/PlainTextCatalog.cpp b/src/tools/locale/PlainTextCatalog.cpp index 00fa5e14de..92dbfb10c3 100644 --- a/src/tools/locale/PlainTextCatalog.cpp +++ b/src/tools/locale/PlainTextCatalog.cpp @@ -122,7 +122,7 @@ PlainTextCatalog::ReadFromFile(const char *path) // Now read all the data from the file // The first line holds some info about the catalog : - // ArchiveVersion \t LanguageName \t Signature \t FingerPrint + // ArchiveVersion \t LanguageName \t AppSignature \t FingerPrint if (std::getline(catalogFile, currentItem, '\t').good()) { // Get the archive version int arcver= -1; @@ -150,7 +150,7 @@ PlainTextCatalog::ReadFromFile(const char *path) if (std::getline(catalogFile, currentItem, '\t').good()) { // Get the language - fLanguageName << currentItem.c_str() ; + fLanguageName = currentItem.c_str() ; } else { fprintf(stderr, "Unable to get language from %s\n", path); return B_ERROR; @@ -158,7 +158,7 @@ PlainTextCatalog::ReadFromFile(const char *path) if (std::getline(catalogFile, currentItem, '\t').good()) { // Get the signature - fSignature << currentItem.c_str() ; + fSignature = currentItem.c_str() ; } else { fprintf(stderr, "Unable to get signature from %s\n", path); return B_ERROR; @@ -175,7 +175,10 @@ PlainTextCatalog::ReadFromFile(const char *path) return B_ERROR; } - if (fFingerprint!=0 && fFingerprint != foundFingerprint) { + if (fFingerprint == 0) + fFingerprint = foundFingerprint; + + if (fFingerprint != foundFingerprint) { return B_MISMATCHED_VALUES; } } else { @@ -185,7 +188,7 @@ PlainTextCatalog::ReadFromFile(const char *path) // We managed to open the file, so we remember it's the one we are using fPath = path; - fprintf(stderr, "found plaintext catalog at %s\n", path); + fprintf(stderr, "LocaleKit Plaintext: found catalog at %s\n", path); std::string originalString; std::string context; @@ -224,6 +227,23 @@ PlainTextCatalog::ReadFromFile(const char *path) catalogFile.close(); + uint32 checkFP = ComputeFingerprint(); + if (fFingerprint != checkFP) { + fprintf(stderr, "plaintext-catalog(sig=%s, lang=%s) " + "has wrong fingerprint after load (%lX instead of %lX). " + "The catalog data may be corrupted, so this catalog is " + "skipped.\n", + fSignature.String(), fLanguageName.String(), checkFP, + fFingerprint); + // TODO: This is what should be done if the fingerprint calculation + // actually worked. Unfortunately, adler32 will not give the same + // results if you swap strings, and an HashMap is not an ordered + // container so you can get a different result each time you iterate + // over it... + + // return B_BAD_DATA; + } + // some information living in member variables needs to be copied // to attributes. Although these attributes should have been written // when creating the catalog, we make sure that they exist there: diff --git a/src/tools/locale/collectcatkeys.cpp b/src/tools/locale/collectcatkeys.cpp index f7825bb858..3fc7289e69 100644 --- a/src/tools/locale/collectcatkeys.cpp +++ b/src/tools/locale/collectcatkeys.cpp @@ -78,7 +78,7 @@ fetchStr(const char *&in, BString &str, bool lookForID) // string (skip escaped quotes) while (*in != '"' || quoted) { - str.Append(in,1); + str.Append(in, 1); if (*in == '\\' && !quoted) quoted = true ; else @@ -143,7 +143,6 @@ fetchKey(const char *&in) haveID = false; // fetch native string or id: if (!fetchStr(in, str, true)) { - fprintf(stderr,"String parsing error\n"); return false; } if (*in == ',') { @@ -187,8 +186,8 @@ collectAllCatalogKeys(BString& inputStr) printf("CatKey(%ld)\n", id); res = catalog->SetString(id, ""); if (res != B_OK) { - fprintf(stderr, "couldn't add key %ld - error: %s\n", - id, strerror(res)); + fprintf(stderr, "Collectcatkeys: couldn't add key %ld - " + "error: %s\n", id, strerror(res)); exit(-1); } } else {