Commit 0cd3ba58 authored by aroben's avatar aroben
Browse files

Change WebLocalizableStrings to take UTF-8 C strings

         This matches the way things work on the Mac, and will allow source
         files containing localizable strings to be shared between Mac and
         Windows. The old functions have not been removed for compatibility
         reasons, but are now just wrappers around the new UTF-8 functions.

         Reviewed by Ada.

         * WebKit.vcproj/WebKit.def: Added new functions.
         * WebKit.vcproj/WebKit_debug.def: Ditto.
         * WebLocalizableStrings.cpp:
         (copyLocalizedStringFromBundle): Changed to take a WebCore::String
         representing the key.
         (localizedString): Refactored from WebLocalizedString. Takes a
         WebCore::String representing the key.
         (localizedLPCTSTR): Ditto for WebLocalizedLPCTSTR.
         (WebLocalizedStringUTF8): Added. Takes a UTF-8 C string as the key.
         (WebLocalizedLPCTSTRUTF8): Ditto.
         (WebLocalizedString): Changed to call localizedString.
         (WebLocalizedLPCTSTR): Changed to call localizedLPCTSTR.
         * WebLocalizableStrings.h: Changed macros to use the new UTF-8
         functions.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@27498 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 43bd3f02
2007-11-06 Adam Roben <aroben@apple.com>
Change WebLocalizableStrings to take UTF-8 C strings
This matches the way things work on the Mac, and will allow source
files containing localizable strings to be shared between Mac and
Windows. The old functions have not been removed for compatibility
reasons, but are now just wrappers around the new UTF-8 functions.
Reviewed by Ada.
* WebKit.vcproj/WebKit.def: Added new functions.
* WebKit.vcproj/WebKit_debug.def: Ditto.
* WebLocalizableStrings.cpp:
(copyLocalizedStringFromBundle): Changed to take a WebCore::String
representing the key.
(localizedString): Refactored from WebLocalizedString. Takes a
WebCore::String representing the key.
(localizedLPCTSTR): Ditto for WebLocalizedLPCTSTR.
(WebLocalizedStringUTF8): Added. Takes a UTF-8 C string as the key.
(WebLocalizedLPCTSTRUTF8): Ditto.
(WebLocalizedString): Changed to call localizedString.
(WebLocalizedLPCTSTR): Changed to call localizedLPCTSTR.
* WebLocalizableStrings.h: Changed macros to use the new UTF-8
functions.
2007-11-06 Darin Adler <darin@apple.com>
 
Reviewed by Adam and Steve.
......
......@@ -87,8 +87,8 @@ EXPORTS
; KJS_JSObject_JSObjectSetMember
; KJS_JSObject_JSObjectSetSlot
; KJS_JSObject_JSObjectToString
WebLocalizedString
WebLocalizedLPCTSTR
WebLocalizedStringUTF8
WebLocalizedLPCTSTRUTF8
SetWebLocalizedStringMainBundle
DrawTextAtPoint
WebDrawText
......@@ -99,3 +99,7 @@ EXPORTS
?fastMalloc@WTF@@YAPAXI@Z
?fastFree@WTF@@YAXPAX@Z
?fastCalloc@WTF@@YAPAXII@Z
; These functions are deprecated
WebLocalizedString
WebLocalizedLPCTSTR
......@@ -87,8 +87,8 @@ EXPORTS
; KJS_JSObject_JSObjectSetMember
; KJS_JSObject_JSObjectSetSlot
; KJS_JSObject_JSObjectToString
WebLocalizedString
WebLocalizedLPCTSTR
WebLocalizedStringUTF8
WebLocalizedLPCTSTRUTF8
SetWebLocalizedStringMainBundle
DrawTextAtPoint
WebDrawText
......@@ -102,3 +102,6 @@ EXPORTS
WTFReportAssertionFailure
WTFReportError
; These functions are deprecated
WebLocalizedString
WebLocalizedLPCTSTR
......@@ -29,6 +29,7 @@
#include "WebLocalizableStrings.h"
#pragma warning(push, 0)
#include <WebCore/CString.h>
#include <WebCore/PlatformString.h>
#include <WebCore/StringHash.h>
#pragma warning(pop)
......@@ -95,7 +96,7 @@ void SetWebLocalizedStringMainBundle(CFBundleRef bundle)
localizedStringsMainBundle = bundle;
}
static CFStringRef copyLocalizedStringFromBundle(WebLocalizableStringsBundle* stringsBundle, LPCTSTR key)
static CFStringRef copyLocalizedStringFromBundle(WebLocalizableStringsBundle* stringsBundle, const String& key)
{
static CFStringRef notFound = CFSTR("localized string not found");
......@@ -117,9 +118,10 @@ static CFStringRef copyLocalizedStringFromBundle(WebLocalizableStringsBundle* st
stringsBundle->bundle = bundle;
}
}
CFStringRef keyString = CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(key), (CFIndex)wcslen(key));
CFStringRef result = CFCopyLocalizedStringWithDefaultValue(keyString, 0, bundle, notFound, 0);
CFRelease(keyString);
RetainPtr<CFStringRef> keyString(AdoptCF, key.createCFString());
CFStringRef result = CFCopyLocalizedStringWithDefaultValue(keyString.get(), 0, bundle, notFound, 0);
ASSERT_WITH_MESSAGE(result != notFound, "could not find localizable string %s in bundle", key);
return result;
}
......@@ -150,33 +152,23 @@ static void cacheString(WebLocalizableStringsBundle* stringsBundle, const String
frameworkLocStrings.set(key, value);
}
CFStringRef WebLocalizedString(WebLocalizableStringsBundle* stringsBundle, LPCTSTR key)
static CFStringRef localizedString(WebLocalizableStringsBundle* stringsBundle, const String& key)
{
if (!key)
return 0;
String keyString(key);
String found;
if (findCachedString(stringsBundle, keyString, found))
if (findCachedString(stringsBundle, key, found))
return found.createCFString();
RetainPtr<CFStringRef> cfStr(AdoptCF, copyLocalizedStringFromBundle(stringsBundle, key));
cacheString(stringsBundle, keyString, cfStr.get());
cacheString(stringsBundle, key, cfStr.get());
return cfStr.releaseRef();
}
LPCTSTR WebLocalizedLPCTSTR(WebLocalizableStringsBundle* stringsBundle, LPCTSTR key)
static LPCTSTR localizedLPCTSTR(WebLocalizableStringsBundle* stringsBundle, const String& key)
{
if (!key)
return 0;
String keyString(key);
String found;
if (findCachedString(stringsBundle, keyString, found))
if (findCachedString(stringsBundle, key, found))
return found.charactersWithNullTermination();
RetainPtr<CFStringRef> cfStr(AdoptCF, copyLocalizedStringFromBundle(stringsBundle, key));
......@@ -187,7 +179,41 @@ LPCTSTR WebLocalizedLPCTSTR(WebLocalizableStringsBundle* stringsBundle, LPCTSTR
str.replace(i, 1, "s");
LPCTSTR lpszStr = str.charactersWithNullTermination();
cacheString(stringsBundle, keyString, str);
cacheString(stringsBundle, key, str);
return lpszStr;
}
CFStringRef WebLocalizedStringUTF8(WebLocalizableStringsBundle* stringsBundle, LPCSTR key)
{
if (!key)
return 0;
return localizedString(stringsBundle, String::fromUTF8(key));
}
LPCTSTR WebLocalizedLPCTSTRUTF8(WebLocalizableStringsBundle* stringsBundle, LPCSTR key)
{
if (!key)
return 0;
return localizedLPCTSTR(stringsBundle, String::fromUTF8(key));
}
// These functions are deprecated.
CFStringRef WebLocalizedString(WebLocalizableStringsBundle* stringsBundle, LPCTSTR key)
{
if (!key)
return 0;
return localizedString(stringsBundle, String(key));
}
LPCTSTR WebLocalizedLPCTSTR(WebLocalizableStringsBundle* stringsBundle, LPCTSTR key)
{
if (!key)
return 0;
return localizedLPCTSTR(stringsBundle, String(key));
}
......@@ -37,9 +37,14 @@ typedef struct {
extern "C" {
#endif
CFStringRef WebLocalizedStringUTF8(WebLocalizableStringsBundle*, LPCSTR key);
LPCTSTR WebLocalizedLPCTSTRUTF8(WebLocalizableStringsBundle*, LPCSTR key);
void SetWebLocalizedStringMainBundle(CFBundleRef bundle);
// These functions are deprecated. Use the UTF-8 versions instead.
CFStringRef WebLocalizedString(WebLocalizableStringsBundle *bundle, LPCTSTR key);
LPCTSTR WebLocalizedLPCTSTR(WebLocalizableStringsBundle *bundle, LPCTSTR key);
void SetWebLocalizedStringMainBundle(CFBundleRef bundle);
#ifdef __cplusplus
}
......@@ -51,17 +56,17 @@ void SetWebLocalizedStringMainBundle(CFBundleRef bundle);
#define LOCALIZABLE_STRINGS_BUNDLE_HELPER(F) F ## LocalizableStringsBundle
extern WebLocalizableStringsBundle LOCALIZABLE_STRINGS_BUNDLE(FRAMEWORK_NAME);
#define UI_STRING(string, comment) WebLocalizedString(&LOCALIZABLE_STRINGS_BUNDLE(FRAMEWORK_NAME), L##string)
#define UI_STRING_KEY(string, key, comment) WebLocalizedString(&LOCALIZABLE_STRINGS_BUNDLE(FRAMEWORK_NAME), L##key)
#define LPCTSTR_UI_STRING(string, comment) WebLocalizedLPCTSTR(&LOCALIZABLE_STRINGS_BUNDLE(FRAMEWORK_NAME), L##string)
#define LPCTSTR_UI_STRING_KEY(string, key, comment) WebLocalizedLPCTSTR(&LOCALIZABLE_STRINGS_BUNDLE(FRAMEWORK_NAME), L##key)
#define UI_STRING(string, comment) WebLocalizedStringUTF8(&LOCALIZABLE_STRINGS_BUNDLE(FRAMEWORK_NAME), string)
#define UI_STRING_KEY(string, key, comment) WebLocalizedStringUTF8(&LOCALIZABLE_STRINGS_BUNDLE(FRAMEWORK_NAME), key)
#define LPCTSTR_UI_STRING(string, comment) WebLocalizedLPCTSTRUTF8(&LOCALIZABLE_STRINGS_BUNDLE(FRAMEWORK_NAME), string)
#define LPCTSTR_UI_STRING_KEY(string, key, comment) WebLocalizedLPCTSTRUTF8(&LOCALIZABLE_STRINGS_BUNDLE(FRAMEWORK_NAME), key)
#else
#define UI_STRING(string, comment) WebLocalizedString(0, L##string)
#define UI_STRING_KEY(string, key, comment) WebLocalizedString(0, L##key)
#define LPCTSTR_UI_STRING(string, comment) WebLocalizedLPCTSTR(0, L##string)
#define LPCTSTR_UI_STRING_KEY(string, key, comment) WebLocalizedLPCTSTR(0, L##key)
#define UI_STRING(string, comment) WebLocalizedStringUTF8(0, string)
#define UI_STRING_KEY(string, key, comment) WebLocalizedStringUTF8(0, key)
#define LPCTSTR_UI_STRING(string, comment) WebLocalizedLPCTSTRUTF8(0, string)
#define LPCTSTR_UI_STRING_KEY(string, key, comment) WebLocalizedLPCTSTRUTF8(0, key)
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment