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

(-)osxlocale.c (-28 / +33 lines)
Lines 2-10 Link Here
2
 *
2
 *
3
 *  $RCSfile: osxlocale.c,v $
3
 *  $RCSfile: osxlocale.c,v $
4
 *
4
 *
5
 *  $Revision: 1.3 $
5
 *  $Revision: 1.2.10.2.4.1 $
6
 *
6
 *
7
 *  last change: $Author: hr $ $Date: 2004/02/02 19:02:19 $
7
 *  last change: $Author: khendricks $ $Date: 2004/08/08 13:44:45 $
8
 *
8
 *
9
 *  The Contents of this file are made available subject to the terms of
9
 *  The Contents of this file are made available subject to the terms of
10
 *  either of the following licenses
10
 *  either of the following licenses
Lines 73-83 Link Here
73
 */
73
 */
74
int macxp_getOSXLocale( char *locale, sal_uInt32 bufferLen )
74
int macxp_getOSXLocale( char *locale, sal_uInt32 bufferLen )
75
{
75
{
76
	LocaleRef		lref;
76
77
#if (BUILD_OS_MAJOR == 10) && (BUILD_OS_MINOR == 2)
78
// Jaguar code
79
	LocaleRef	lref;
77
	CFArrayRef	aref;
80
	CFArrayRef	aref;
78
	CFStringRef	sref;
81
	CFStringRef	sref;
79
	CFStringRef    locNameRef;
82
	CFStringRef    locNameRef;
80
     
83
81
	aref = (CFArrayRef)CFPreferencesCopyAppValue( CFSTR( "AppleLanguages" ), kCFPreferencesCurrentApplication );
84
	aref = (CFArrayRef)CFPreferencesCopyAppValue( CFSTR( "AppleLanguages" ), kCFPreferencesCurrentApplication );
82
	if ( aref != NULL )
85
	if ( aref != NULL )
83
	{
86
	{
Lines 86-114 Link Here
86
			sref = (CFStringRef)CFArrayGetValueAtIndex( aref, 0 );
89
			sref = (CFStringRef)CFArrayGetValueAtIndex( aref, 0 );
87
			if ( (sref != NULL) && (CFGetTypeID(sref) == CFStringGetTypeID()) )
90
			if ( (sref != NULL) && (CFGetTypeID(sref) == CFStringGetTypeID()) )
88
			{
91
			{
89
#if (BUILD_OS_MAJOR==10) && (BUILD_OS_MINOR==3)
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() ) )
92
				if ( CFStringGetCString( sref, locale, bufferLen, CFStringGetSystemEncoding() ) )
113
				{
93
				{
114
					LocaleRefFromLocaleString( locale, &lref );
94
					LocaleRefFromLocaleString( locale, &lref );
Lines 119-126 Link Here
119
					*/
99
					*/
120
					if ( (strlen(locale) == 2) && (strncmp(locale, "en", 2) == 0) )
100
					if ( (strlen(locale) == 2) && (strncmp(locale, "en", 2) == 0) )
121
						strncat( locale, "_US", bufferLen - strlen(locale) - 1 );
101
						strncat( locale, "_US", bufferLen - strlen(locale) - 1 );
102
        				// For Japanese locale, just "ja" is not sufficient.
103
					// Use "ja_JP.UTF-8" instead.
104
					if ( (strlen(locale) == 2) && (strncmp(locale, "ja", 2) == 0) )
105
						strlcpy( locale, "ja_JP.UTF-8", bufferLen );
122
				}
106
				}
123
#endif
124
			}
107
			}
125
			else
108
			else
126
				fprintf( stderr, "Could not get array index 0 value of CFPref AppleLanguages!\n" );
109
				fprintf( stderr, "Could not get array index 0 value of CFPref AppleLanguages!\n" );
Lines 132-137 Link Here
132
          fprintf( stderr, "Could not get value of CFPref AppleLanguages!  Please reset your locale in the International control panel.\n" );
115
          fprintf( stderr, "Could not get value of CFPref AppleLanguages!  Please reset your locale in the International control panel.\n" );
133
116
134
	return( noErr );
117
	return( noErr );
118
119
#else 
120
// Panther and later code
121
122
        CFStringRef lstr;
123
        CFLocaleRef lref;
124
125
        lref = CFLocaleCopyCurrent();
126
        lstr = CFLocaleGetIdentifier(lref);
127
        CFStringGetCString(lstr, locale, bufferLen, kCFStringEncodingASCII);
128
        CFRelease(lref);
129
        CFRelease(lstr);
130
131
        if ( strchr(locale, '.') == NULL )
132
	  strlcat( locale, ".UTF-8", bufferLen );
133
134
        // fprintf(stderr,"returned locale string is %s\n",locale);
135
136
        return ( noErr );
137
138
#endif
139
135
}
140
}
136
141
137
142

Return to issue 46963