View | Details | Raw Unified | Return to issue 25416
Collapse All | Expand All

(-)/so/env/O-Laufwerk/SRC680/src.m109/sal/systools/macxp_extras/x11osx/osxlocale.c (-56 / +30 lines)
Lines 1-3 Link Here
1
1
/*************************************************************************
2
/*************************************************************************
2
 *
3
 *
3
 *  $RCSfile: osxlocale.c,v $
4
 *  $RCSfile: osxlocale.c,v $
Lines 72-137 Link Here
72
 * Grab current locale from system.
73
 * Grab current locale from system.
73
 */
74
 */
74
int macxp_getOSXLocale( char *locale, sal_uInt32 bufferLen )
75
int macxp_getOSXLocale( char *locale, sal_uInt32 bufferLen )
75
{
76
{	
76
	LocaleRef		lref;
77
	CFStringRef sref = (CFStringRef)CFPreferencesCopyAppValue(CFSTR("AppleLocale"), kCFPreferencesCurrentApplication);
77
	CFArrayRef	aref;
78
		
78
	CFStringRef	sref;
79
	if ((sref != NULL) && (CFGetTypeID(sref) == CFStringGetTypeID()))
79
	CFStringRef    locNameRef;
80
     
81
	aref = (CFArrayRef)CFPreferencesCopyAppValue( CFSTR( "AppleLanguages" ), kCFPreferencesCurrentApplication );
82
	if ( aref != NULL )
83
	{
80
	{
84
		if ( (CFGetTypeID(aref) == CFArrayGetTypeID()) && (CFArrayGetCount(aref) > 0) )
81
		// split the string into substrings; the first two (if there are two) substrings 
82
		// are language and country
83
		CFArrayRef subs = CFStringCreateArrayBySeparatingStrings(NULL, sref, CFSTR("_"));
84
		
85
		CFStringRef lang = (CFStringRef)CFArrayGetValueAtIndex(subs, 0);
86
		CFStringGetCString(lang, locale, bufferLen, kCFStringEncodingASCII);
87
		
88
		// country also available? Assumption: if the array contains more than one
89
		// value the second value is always the country!
90
		if (CFArrayGetCount(subs) > 1)
85
		{
91
		{
86
			sref = (CFStringRef)CFArrayGetValueAtIndex( aref, 0 );
92
			strlcat(locale, "_", bufferLen - strlen(locale));
87
			if ( (sref != NULL) && (CFGetTypeID(sref) == CFStringGetTypeID()) )
93
			
88
			{
94
			CFStringRef country = (CFStringRef)CFArrayGetValueAtIndex(subs, 1);
89
#if (BUILD_OS_MAJOR==10) && (BUILD_OS_MINOR==3)
95
			CFStringGetCString(country, locale + strlen(locale), bufferLen - strlen(locale), kCFStringEncodingASCII);			
90
// Panther code
91
				// This function only exists in Panther and above
92
				locNameRef = CFLocaleCreateCanonicalLocaleIdentifierFromString( kCFAllocatorDefault,  sref );
93
94
				if ( locNameRef != NULL )
95
				{
96
					CFStringGetCString( locNameRef, locale, bufferLen, kCFStringEncodingASCII );
97
					CFRelease( locNameRef );
98
99
					// If its just en, we want en_US.  Since all the locales are also
100
					// UTF-8, we'll append UTF-8 to the end of all returned locales
101
					if ( strcmp(locale, "en") == 0 )
102
						strlcpy( locale, "en_US", bufferLen );
103
//					else if ( strchr(locale, '.') == NULL )
104
//						strlcat( locale, ".UTF-8", bufferLen );
105
				}
106
				else
107
					fprintf( stderr, "Could not get Canonical Locale Identifier from AppleLanguages value!\n" );
108
#endif
109
110
#if (BUILD_OS_MAJOR == 10) && (BUILD_OS_MINOR == 2)
111
// Jaguar code
112
				if ( CFStringGetCString( sref, locale, bufferLen, CFStringGetSystemEncoding() ) )
113
				{
114
					LocaleRefFromLocaleString( locale, &lref );
115
					LocaleRefGetPartString( lref, kLocaleAllPartsMask, bufferLen, locale );
116
117
					/* Hack for US english locales.  OS X returns only "en", but we want
118
					* "en_US".  So add it.
119
					*/
120
					if ( (strlen(locale) == 2) && (strncmp(locale, "en", 2) == 0) )
121
						strncat( locale, "_US", bufferLen - strlen(locale) - 1 );
122
				}
123
#endif
124
			}
125
			else
126
				fprintf( stderr, "Could not get array index 0 value of CFPref AppleLanguages!\n" );
127
		}
96
		}
97
		
98
		strlcat(locale, ".UTF-8", bufferLen - strlen(locale));							
99
		
100
		CFRelease(subs);
101
	}
102
	else
103
		fprintf( stderr, "Could not get Canonical Locale Identifier from AppleLanguages value!\n" );
128
104
129
		CFRelease( aref );
105
    CFRelease(sref);
130
     }
106
	
131
     else
107
	return noErr;
132
          fprintf( stderr, "Could not get value of CFPref AppleLanguages!  Please reset your locale in the International control panel.\n" );
133
134
	return( noErr );
135
}
108
}
136
109
137
110
Lines 149-151 Link Here
149
122
150
	return( noErr );
123
	return( noErr );
151
}
124
}
125

Return to issue 25416