1 // Copyright 2006-2011 the V8 project authors. All rights reserved. 2 // Redistribution and use in source and binary forms, with or without 3 // modification, are permitted provided that the following conditions are 4 // met: 5 // 6 // * Redistributions of source code must retain the above copyright 7 // notice, this list of conditions and the following disclaimer. 8 // * Redistributions in binary form must reproduce the above 9 // copyright notice, this list of conditions and the following 10 // disclaimer in the documentation and/or other materials provided 11 // with the distribution. 12 // * Neither the name of Google Inc. nor the names of its 13 // contributors may be used to endorse or promote products derived 14 // from this software without specific prior written permission. 15 // 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28 // TODO(cira): Remove v8 prefix from v8Locale once we have stable API. 29 v8Locale = function(optLocale) { 30 native function NativeJSLocale(); 31 var properties = NativeJSLocale(optLocale); 32 this.locale = properties.locale; 33 this.language = properties.language; 34 this.script = properties.script; 35 this.region = properties.region; 36 }; 37 38 v8Locale.availableLocales = function() { 39 native function NativeJSAvailableLocales(); 40 return NativeJSAvailableLocales(); 41 }; 42 43 v8Locale.prototype.maximizedLocale = function() { 44 native function NativeJSMaximizedLocale(); 45 return new v8Locale(NativeJSMaximizedLocale(this.locale)); 46 }; 47 48 v8Locale.prototype.minimizedLocale = function() { 49 native function NativeJSMinimizedLocale(); 50 return new v8Locale(NativeJSMinimizedLocale(this.locale)); 51 }; 52 53 v8Locale.prototype.displayLocale_ = function(displayLocale) { 54 var result = this.locale; 55 if (displayLocale !== undefined) { 56 result = displayLocale.locale; 57 } 58 return result; 59 }; 60 61 v8Locale.prototype.displayLanguage = function(optDisplayLocale) { 62 var displayLocale = this.displayLocale_(optDisplayLocale); 63 native function NativeJSDisplayLanguage(); 64 return NativeJSDisplayLanguage(this.locale, displayLocale); 65 }; 66 67 v8Locale.prototype.displayScript = function(optDisplayLocale) { 68 var displayLocale = this.displayLocale_(optDisplayLocale); 69 native function NativeJSDisplayScript(); 70 return NativeJSDisplayScript(this.locale, displayLocale); 71 }; 72 73 v8Locale.prototype.displayRegion = function(optDisplayLocale) { 74 var displayLocale = this.displayLocale_(optDisplayLocale); 75 native function NativeJSDisplayRegion(); 76 return NativeJSDisplayRegion(this.locale, displayLocale); 77 }; 78 79 v8Locale.prototype.displayName = function(optDisplayLocale) { 80 var displayLocale = this.displayLocale_(optDisplayLocale); 81 native function NativeJSDisplayName(); 82 return NativeJSDisplayName(this.locale, displayLocale); 83 }; 84 85 v8Locale.v8BreakIterator = function(locale, type) { 86 native function NativeJSBreakIterator(); 87 var iterator = NativeJSBreakIterator(locale, type); 88 iterator.type = type; 89 return iterator; 90 }; 91 92 v8Locale.v8BreakIterator.BreakType = { 93 'unknown': -1, 94 'none': 0, 95 'number': 100, 96 'word': 200, 97 'kana': 300, 98 'ideo': 400 99 }; 100 101 v8Locale.prototype.v8CreateBreakIterator = function(type) { 102 return new v8Locale.v8BreakIterator(this.locale, type); 103 }; 104