| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 160 |
| 161 return locale; | 161 return locale; |
| 162 } | 162 } |
| 163 | 163 |
| 164 // TODO(cira): Filter out locales that Chrome doesn't support. | 164 // TODO(cira): Filter out locales that Chrome doesn't support. |
| 165 v8::Handle<v8::Value> I18NExtension::JSAvailableLocales( | 165 v8::Handle<v8::Value> I18NExtension::JSAvailableLocales( |
| 166 const v8::Arguments& args) { | 166 const v8::Arguments& args) { |
| 167 v8::Local<v8::Array> all_locales = v8::Array::New(); | 167 v8::Local<v8::Array> all_locales = v8::Array::New(); |
| 168 | 168 |
| 169 int count = 0; | 169 int count = 0; |
| 170 const icu::Locale* icu_locales = icu::Locale::getAvailableLocales(count); | 170 const Locale* icu_locales = icu::Locale::getAvailableLocales(count); |
| 171 for (int i = 0; i < count; ++i) { | 171 for (int i = 0; i < count; ++i) { |
| 172 all_locales->Set(i, v8::String::New(icu_locales[i].getName())); | 172 all_locales->Set(i, v8::String::New(icu_locales[i].getName())); |
| 173 } | 173 } |
| 174 | 174 |
| 175 return all_locales; | 175 return all_locales; |
| 176 } | 176 } |
| 177 | 177 |
| 178 // Use - as tag separator, not _ that ICU uses. | 178 // Use - as tag separator, not _ that ICU uses. |
| 179 static std::string NormalizeLocale(const std::string& locale) { | 179 static std::string NormalizeLocale(const std::string& locale) { |
| 180 std::string result(locale); | 180 std::string result(locale); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 static v8::Handle<v8::Value> GetDisplayItem(const v8::Arguments& args, | 223 static v8::Handle<v8::Value> GetDisplayItem(const v8::Arguments& args, |
| 224 const std::string& item) { | 224 const std::string& item) { |
| 225 if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsString()) { | 225 if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsString()) { |
| 226 return v8::Undefined(); | 226 return v8::Undefined(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 std::string base_locale = *v8::String::Utf8Value(args[0]->ToString()); | 229 std::string base_locale = *v8::String::Utf8Value(args[0]->ToString()); |
| 230 icu::Locale icu_locale(base_locale.c_str()); | 230 icu::Locale icu_locale(base_locale.c_str()); |
| 231 icu::Locale display_locale = | 231 icu::Locale display_locale = |
| 232 icu::Locale(*v8::String::Utf8Value(args[1]->ToString())); | 232 icu::Locale(*v8::String::Utf8Value(args[1]->ToString())); |
| 233 icu::UnicodeString result; | 233 UnicodeString result; |
| 234 if (item == "language") { | 234 if (item == "language") { |
| 235 icu_locale.getDisplayLanguage(display_locale, result); | 235 icu_locale.getDisplayLanguage(display_locale, result); |
| 236 } else if (item == "script") { | 236 } else if (item == "script") { |
| 237 icu_locale.getDisplayScript(display_locale, result); | 237 icu_locale.getDisplayScript(display_locale, result); |
| 238 } else if (item == "region") { | 238 } else if (item == "region") { |
| 239 icu_locale.getDisplayCountry(display_locale, result); | 239 icu_locale.getDisplayCountry(display_locale, result); |
| 240 } else if (item == "name") { | 240 } else if (item == "name") { |
| 241 icu_locale.getDisplayName(display_locale, result); | 241 icu_locale.getDisplayName(display_locale, result); |
| 242 } else { | 242 } else { |
| 243 return v8::Undefined(); | 243 return v8::Undefined(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 extension_ = new I18NExtension(); | 275 extension_ = new I18NExtension(); |
| 276 } | 276 } |
| 277 return extension_; | 277 return extension_; |
| 278 } | 278 } |
| 279 | 279 |
| 280 void I18NExtension::Register() { | 280 void I18NExtension::Register() { |
| 281 static v8::DeclareExtension i18n_extension_declaration(I18NExtension::get()); | 281 static v8::DeclareExtension i18n_extension_declaration(I18NExtension::get()); |
| 282 } | 282 } |
| 283 | 283 |
| 284 } } // namespace v8::internal | 284 } } // namespace v8::internal |
| OLD | NEW |