Source code

Revision control

Other Tools

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_IntlObject_h
8
#define builtin_intl_IntlObject_h
9
10
#include "mozilla/Attributes.h"
11
12
#include "js/RootingAPI.h"
13
#include "js/TypeDecls.h"
14
15
namespace js {
16
17
class GlobalObject;
18
19
extern const JSClass IntlClass;
20
21
/**
22
* Initializes the Intl Object and its standard built-in properties.
23
* Spec: ECMAScript Internationalization API Specification, 8.0, 8.1
24
*/
25
extern JSObject* InitIntlClass(JSContext* cx, JS::Handle<GlobalObject*> global);
26
27
/**
28
* Returns a plain object with calendar information for a single valid locale
29
* (callers must perform this validation). The object will have these
30
* properties:
31
*
32
* firstDayOfWeek
33
* an integer in the range 1=Sunday to 7=Saturday indicating the day
34
* considered the first day of the week in calendars, e.g. 1 for en-US,
35
* 2 for en-GB, 1 for bn-IN
36
* minDays
37
* an integer in the range of 1 to 7 indicating the minimum number
38
* of days required in the first week of the year, e.g. 1 for en-US,
39
* 4 for de
40
* weekendStart
41
* an integer in the range 1=Sunday to 7=Saturday indicating the day
42
* considered the beginning of a weekend, e.g. 7 for en-US, 7 for en-GB,
43
* 1 for bn-IN
44
* weekendEnd
45
* an integer in the range 1=Sunday to 7=Saturday indicating the day
46
* considered the end of a weekend, e.g. 1 for en-US, 1 for en-GB,
47
* 1 for bn-IN (note that "weekend" is *not* necessarily two days)
48
*
49
* NOTE: "calendar" and "locale" properties are *not* added to the object.
50
*/
51
extern MOZ_MUST_USE bool intl_GetCalendarInfo(JSContext* cx, unsigned argc,
52
JS::Value* vp);
53
54
/**
55
* Returns a plain object with locale information for a single valid locale
56
* (callers must perform this validation). The object will have these
57
* properties:
58
*
59
* direction
60
* a string with a value "ltr" for left-to-right locale, and "rtl" for
61
* right-to-left locale.
62
* locale
63
* a BCP47 compilant locale string for the resolved locale.
64
*/
65
extern MOZ_MUST_USE bool intl_GetLocaleInfo(JSContext* cx, unsigned argc,
66
JS::Value* vp);
67
68
/**
69
* Returns an Array with CLDR-based fields display names.
70
* The function takes three arguments:
71
*
72
* locale
73
* BCP47 compliant locale string
74
* style
75
* A string with values: long or short or narrow
76
* keys
77
* An array or path-like strings that identify keys to be returned
78
* At the moment the following types of keys are supported:
79
*
80
* 'dates/fields/{year|month|week|day}'
81
* 'dates/gregorian/months/{january|...|december}'
82
* 'dates/gregorian/weekdays/{sunday|...|saturday}'
83
* 'dates/gregorian/dayperiods/{am|pm}'
84
*
85
* Example:
86
*
87
* let info = intl_ComputeDisplayNames(
88
* 'en-US',
89
* 'long',
90
* [
91
* 'dates/fields/year',
92
* 'dates/gregorian/months/january',
93
* 'dates/gregorian/weekdays/monday',
94
* 'dates/gregorian/dayperiods/am',
95
* ]
96
* );
97
*
98
* Returned value:
99
*
100
* [
101
* 'year',
102
* 'January',
103
* 'Monday',
104
* 'AM'
105
* ]
106
*/
107
extern MOZ_MUST_USE bool intl_ComputeDisplayNames(JSContext* cx, unsigned argc,
108
JS::Value* vp);
109
/**
110
* Compares a BCP 47 language tag against the locales in availableLocales and
111
* returns the best available match -- or |undefined| if no match was found.
112
* Uses the fallback mechanism of RFC 4647, section 3.4.
113
*
114
* The set of available locales consulted doesn't necessarily include the
115
* default locale or any generalized forms of it (e.g. "de" is a more-general
116
* form of "de-CH"). If you want to be sure to consider the default local and
117
* its generalized forms (you usually will), pass the default locale as the
118
* value of |defaultOrNull|; otherwise pass null.
119
*
120
* Spec: ECMAScript Internationalization API Specification, 9.2.2.
121
* Spec: RFC 4647, section 3.4.
122
*
123
* Usage: result = intl_BestAvailableLocale("Collator", locale, defaultOrNull)
124
*/
125
extern MOZ_MUST_USE bool intl_BestAvailableLocale(JSContext* cx, unsigned argc,
126
JS::Value* vp);
127
128
/**
129
* Returns the input locale in its canonicalized form if ICU supports that
130
* locale (perhaps via fallback, e.g. supporting "de-ZA" through "de" support
131
* implied by a "de-DE" locale). Otherwise uses the last-ditch locale.
132
*
133
* Usage: result = intl_supportedLocaleOrFallback(locale)
134
*/
135
extern MOZ_MUST_USE bool intl_supportedLocaleOrFallback(JSContext* cx,
136
unsigned argc,
137
JS::Value* vp);
138
139
} // namespace js
140
141
#endif /* builtin_intl_IntlObject_h */