From f03bf767b821f2f8e0a22e5d3422f4e5dfae8a2d Mon Sep 17 00:00:00 2001 From: skeezix Date: Mon, 1 Mar 2010 23:07:13 -0500 Subject: [PATCH] Fix for getting .de when you wanted .en for example.. slightly better(?) isolang best matcher --- lib/pnd_pxml.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/pnd_pxml.c b/lib/pnd_pxml.c index 836a970..2cde635 100644 --- a/lib/pnd_pxml.c +++ b/lib/pnd_pxml.c @@ -10,6 +10,7 @@ #include "pnd_pxml.h" #include "pnd_pathiter.h" #include "pnd_tinyxml.h" +#include "pnd_logger.h" pnd_pxml_handle *pnd_pxml_fetch ( char *fullpath ) { FILE *f; @@ -283,12 +284,17 @@ signed char pnd_pxml_merge_override ( pnd_pxml_handle h, char *searchpath ) { char *pnd_pxml_get_best_localized_string(pnd_localized_string_t strings[], int strings_c, char *iso_lang) { int i; - int similarity_weight = 0xff; /*Set to something Really Bad in the beginning*/ + int similarity_weight = 0xffff; /*Set to something Really Bad in the beginning*/ char *best_match = NULL; for(i = 0; i < strings_c; i++) { - int new_weight = abs(strcmp(strings[i].language, iso_lang)); + // factor in the length -- if we're given 'en' and have a string 'en_US', thats better than 'de_something'; if we don't + // use length, then en_US and de_FO are same to 'en'. + int maxcount = strlen ( strings[i].language ) < strlen ( iso_lang ) ? strlen ( strings[i].language ) : strlen ( iso_lang ); + int new_weight = abs(strncmp(strings[i].language, iso_lang, maxcount)); + //pnd_log ( PND_LOG_DEFAULT, "looking for lang %s, looking at lang %s (weight %d, old %d): %s\n", + // iso_lang, strings [ i ].language, new_weight, similarity_weight, strings [ i ].string ); if (new_weight < similarity_weight) { similarity_weight = new_weight; @@ -297,9 +303,12 @@ char *pnd_pxml_get_best_localized_string(pnd_localized_string_t strings[], int s } if ( best_match ) { + //pnd_log ( PND_LOG_DEFAULT, "best match: %s\n", best_match ); return strdup(best_match); } + //pnd_log ( PND_LOG_DEFAULT, "best match: FAIL\n" ); + return ( NULL ); } -- 2.39.2