2626#include "internal_territory_names_local.h"
2727#include "internal_alphabet_recognizer.h"
2828
29+ // We must have a default language
30+ #define MAPCODE_SUPPORT_LANGUAGE_EN
31+ #define DEFAULT_TERRITORY_FULL_NAME TERRITORY_FULL_NAME_EN
32+
2933#include "internal_territory_names_da.h"
3034#include "internal_territory_names_de.h"
3135#include "internal_territory_names_en.h"
@@ -106,6 +110,19 @@ static const double METERS_PER_DEGREE_LON = EARTH_CIRCUMFERENCE_X / 360.0;
106110
107111static const int DEBUG_STOP_AT = -1 ; // to externally test-restrict internal encoding, do not use!
108112
113+ typedef struct {
114+ const char * locale ;
115+ const char * * territoryFullNames ;
116+ } LocaleRegistryItem ;
117+
118+ static const LocaleRegistryItem LOCALE_REGISTRY [] = {
119+ {"DA" , TERRITORY_FULL_NAME_DA },
120+ {"DE" , TERRITORY_FULL_NAME_DE },
121+ {"EN" , TERRITORY_FULL_NAME_EN },
122+ {"FR" , TERRITORY_FULL_NAME_FR },
123+ {"NL" , TERRITORY_FULL_NAME_NL }
124+ };
125+
109126// important information about the 8 parents
110127static const char * PARENTS_3 = "USA,IND,CAN,AUS,MEX,BRA,RUS,CHN," ;
111128static const char * PARENTS_2 = "US,IN,CA,AU,MX,BR,RU,CN," ;
@@ -3023,19 +3040,6 @@ const TerritoryAlphabets *getAlphabetsForTerritory(enum Territory territory) {
30233040//
30243041///////////////////////////////////////////////////////////////////////////////////////////////
30253042
3026- typedef struct {
3027- const char * locale ;
3028- const char * * territoryFullnames ;
3029- } LocaleRegistryItem ;
3030-
3031- static const LocaleRegistryItem LOCALE_REGISTRY [] = {
3032- { "DA" , TERRITORY_FULL_NAME_DA },
3033- { "DE" , TERRITORY_FULL_NAME_DE },
3034- { "EN" , TERRITORY_FULL_NAME_EN },
3035- { "FR" , TERRITORY_FULL_NAME_FR },
3036- { "NL" , TERRITORY_FULL_NAME_NL }
3037- };
3038-
30393043static int getFullTerritoryName_internal (
30403044 char * territoryName ,
30413045 enum Territory territory ,
@@ -3046,34 +3050,42 @@ static int getFullTerritoryName_internal(
30463050 const char * s ;
30473051 const char * pipePtr ;
30483052 const char * * namelist = NULL ;
3049- char localeUpper [3 ] = "" ;
30503053
30513054 ASSERT (territoryName );
30523055
3053- if ((! locale && ( strlen ( locale ) < 2 )) || alternative < 0 || territory <= _TERRITORY_MIN || territory >= _TERRITORY_MAX ) {
3056+ if (alternative < 0 || territory <= _TERRITORY_MIN || territory >= _TERRITORY_MAX ) {
30543057 * territoryName = 0 ;
30553058 return 0 ;
30563059 }
3057- localeUpper [0 ] = locale [0 ];
3058- localeUpper [1 ] = locale [1 ];
3059- localeUpper [2 ] = 0 ;
30603060
30613061 if (locale == NULL ) {
3062+
3063+ // Use local names if locale is null.
30623064 namelist = TERRITORY_FULL_NAME_LOCAL ;
3065+ } else if (strlen (locale ) < 2 ) {
3066+
3067+ // Locale is invalid.
3068+ namelist = NULL ;
30633069 } else {
3070+
3071+ // Try and get correct list.
3072+ char localeUpper [3 ] = "" ;
30643073 int i ;
3074+ localeUpper [0 ] = locale [0 ];
3075+ localeUpper [1 ] = locale [1 ];
3076+ localeUpper [2 ] = 0 ;
30653077 namelist = NULL ;
30663078 for (i = 0 ; i < (int ) (sizeof (LOCALE_REGISTRY ) / sizeof (LOCALE_REGISTRY [0 ])); ++ i ) {
3067- if (strcmp (LOCALE_REGISTRY [i ].locale , localeUpper )) {
3068- namelist = LOCALE_REGISTRY [i ].territoryFullnames ;
3079+ if (! strcmp (LOCALE_REGISTRY [i ].locale , localeUpper )) {
3080+ namelist = LOCALE_REGISTRY [i ].territoryFullNames ;
30693081 break ;
30703082 }
30713083 }
30723084 }
30733085
3086+ // Use English if locale is invalid.
30743087 if (namelist == NULL || namelist [0 ] == NULL ) {
3075- * territoryName = 0 ;
3076- return 0 ;
3088+ namelist = DEFAULT_TERRITORY_FULL_NAME ;
30773089 }
30783090
30793091 s = namelist [INDEX_OF_TERRITORY (territory )];
0 commit comments