Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/closure/goog/locale/genericfontnames.js
2868 views
1
// Copyright 2008 The Closure Library Authors. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS-IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
/**
16
* @fileoverview Functions to list locale-specific font list and generic name.
17
* Generic name used for a font family would be locale dependent. For example,
18
* for 'zh'(Chinese) users, the name for Serif family would be in Chinese.
19
* Further documentation at: http://go/genericfontnames.
20
*/
21
22
goog.provide('goog.locale.genericFontNames');
23
24
25
/**
26
* This object maps (resourceName, localeName) to a resourceObj.
27
* @type {Object}
28
* @private
29
*/
30
goog.locale.genericFontNames.data_ = {};
31
32
33
/**
34
* Normalizes the given locale id to standard form. eg: zh_Hant_TW.
35
* Many a times, input locale would be like: zh-tw, zh-hant-tw.
36
* @param {string} locale The locale id to be normalized.
37
* @return {string} Normalized locale id.
38
* @private
39
*/
40
goog.locale.genericFontNames.normalize_ = function(locale) {
41
locale = locale.replace(/-/g, '_');
42
locale =
43
locale.replace(/_[a-z]{2}$/, function(str) { return str.toUpperCase(); });
44
45
locale = locale.replace(/[a-z]{4}/, function(str) {
46
return str.substring(0, 1).toUpperCase() + str.substring(1);
47
});
48
return locale;
49
};
50
51
52
/**
53
* Gets the list of fonts and their generic names for the given locale.
54
* @param {string} locale The locale for which font lists and font family names
55
* to be produced. The expected locale id is as described in
56
* http://wiki/Main/IIISynonyms in all lowercase for easy matching.
57
* Smallest possible id is expected.
58
* Examples: 'zh', 'zh-tw', 'iw' instead of 'zh-CN', 'zh-Hant-TW', 'he'.
59
* @return {Array<Object>} List of objects with generic name as 'caption' and
60
* corresponding font name lists as 'value' property.
61
*/
62
goog.locale.genericFontNames.getList = function(locale) {
63
64
locale = goog.locale.genericFontNames.normalize_(locale);
65
if (locale in goog.locale.genericFontNames.data_) {
66
return goog.locale.genericFontNames.data_[locale];
67
}
68
return [];
69
};
70
71