tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

LocaleNegotiation.h (2646B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: set ts=8 sts=2 et sw=2 tw=80:
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef builtin_intl_LocaleNegotiation_h
      8 #define builtin_intl_LocaleNegotiation_h
      9 
     10 #include "js/RootingAPI.h"
     11 #include "js/TypeDecls.h"
     12 
     13 class JSLinearString;
     14 
     15 namespace js {
     16 class ArrayObject;
     17 }
     18 
     19 namespace js::intl {
     20 
     21 enum class AvailableLocaleKind;
     22 
     23 using LocalesList = JS::StackGCVector<JSLinearString*>;
     24 
     25 /**
     26 * Canonicalizes a locale list.
     27 *
     28 * Spec: ECMAScript Internationalization API Specification, 9.2.1.
     29 */
     30 bool CanonicalizeLocaleList(JSContext* cx, JS::Handle<JS::Value> locales,
     31                            JS::MutableHandle<LocalesList> result);
     32 
     33 ArrayObject* LocalesListToArray(JSContext* cx, JS::Handle<LocalesList> locales);
     34 
     35 /**
     36 * Compares a BCP 47 language tag against the locales in availableLocales and
     37 * returns the best available match -- or |nullptr| if no match was found.
     38 * Uses the fallback mechanism of RFC 4647, section 3.4.
     39 *
     40 * The set of available locales consulted doesn't necessarily include the
     41 * default locale or any generalized forms of it (e.g. "de" is a more-general
     42 * form of "de-CH"). If you want to be sure to consider the default local and
     43 * its generalized forms (you usually will), pass the default locale as the
     44 * value of |defaultLocale|; otherwise pass |nullptr|.
     45 *
     46 * Spec: ECMAScript Internationalization API Specification, 9.2.2.
     47 * Spec: RFC 4647, section 3.4.
     48 */
     49 bool BestAvailableLocale(JSContext* cx, AvailableLocaleKind availableLocales,
     50                         JS::Handle<JSLinearString*> locale,
     51                         JS::Handle<JSLinearString*> defaultLocale,
     52                         JS::MutableHandle<JSLinearString*> result);
     53 
     54 /**
     55 * Return the supported locales in |locales| which are supported according to
     56 * |availableLocales|.
     57 */
     58 ArrayObject* SupportedLocalesOf(JSContext* cx,
     59                                AvailableLocaleKind availableLocales,
     60                                JS::Handle<JS::Value> locales,
     61                                JS::Handle<JS::Value> options);
     62 
     63 /**
     64 * Return the supported locale for the default locale if ICU supports that
     65 * default locale (perhaps via fallback, e.g. supporting "de-CH" through "de"
     66 * support implied by a "de-DE" locale). Otherwise uses the last-ditch locale.
     67 */
     68 JSLinearString* ComputeDefaultLocale(JSContext* cx);
     69 
     70 }  // namespace js::intl
     71 
     72 #endif /* builtin_intl_LocaleNegotiation_h */