Path: blob/trunk/third_party/closure/goog/locale/genericfontnames.js
2868 views
// Copyright 2008 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Functions to list locale-specific font list and generic name.16* Generic name used for a font family would be locale dependent. For example,17* for 'zh'(Chinese) users, the name for Serif family would be in Chinese.18* Further documentation at: http://go/genericfontnames.19*/2021goog.provide('goog.locale.genericFontNames');222324/**25* This object maps (resourceName, localeName) to a resourceObj.26* @type {Object}27* @private28*/29goog.locale.genericFontNames.data_ = {};303132/**33* Normalizes the given locale id to standard form. eg: zh_Hant_TW.34* Many a times, input locale would be like: zh-tw, zh-hant-tw.35* @param {string} locale The locale id to be normalized.36* @return {string} Normalized locale id.37* @private38*/39goog.locale.genericFontNames.normalize_ = function(locale) {40locale = locale.replace(/-/g, '_');41locale =42locale.replace(/_[a-z]{2}$/, function(str) { return str.toUpperCase(); });4344locale = locale.replace(/[a-z]{4}/, function(str) {45return str.substring(0, 1).toUpperCase() + str.substring(1);46});47return locale;48};495051/**52* Gets the list of fonts and their generic names for the given locale.53* @param {string} locale The locale for which font lists and font family names54* to be produced. The expected locale id is as described in55* http://wiki/Main/IIISynonyms in all lowercase for easy matching.56* Smallest possible id is expected.57* Examples: 'zh', 'zh-tw', 'iw' instead of 'zh-CN', 'zh-Hant-TW', 'he'.58* @return {Array<Object>} List of objects with generic name as 'caption' and59* corresponding font name lists as 'value' property.60*/61goog.locale.genericFontNames.getList = function(locale) {6263locale = goog.locale.genericFontNames.normalize_(locale);64if (locale in goog.locale.genericFontNames.data_) {65return goog.locale.genericFontNames.data_[locale];66}67return [];68};697071