| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
djConfig={baseUrl: "../../../dojo/", paths: {"dojo/_base/xhr": "../util/buildscripts/cldr/xhr"}}; |
| 13 |
|
| 14 |
load("../../../dojo/dojo.js"); |
| 15 |
load("../jslib/logger.js"); |
| 16 |
load("../jslib/fileUtil.js"); |
| 17 |
load("cldrUtil.js"); |
| 18 |
|
| 19 |
dojo.require("dojo.i18n"); |
| 20 |
|
| 21 |
var dir = arguments[0]; |
| 22 |
var logDir = arguments[1]; |
| 23 |
var logStr = ""; |
| 24 |
|
| 25 |
|
| 26 |
var BUNDLES = ['gregorian','hebrew','islamic','islamic-civil','buddhist','persian']; |
| 27 |
|
| 28 |
var LOCALE_ALIAS_MARK = '@localeAlias'; |
| 29 |
var LOCALE_ALIAS_SOURCE_PROPERTY = 'source'; |
| 30 |
var LOCALE_ALIAS_TARGET_PROPERTY = 'target'; |
| 31 |
var LOCALE_ALIAS_TARGET_BUNDLE = 'bundle'; |
| 32 |
var localeAliasPaths = []; |
| 33 |
var records = {}; |
| 34 |
var updated = false; |
| 35 |
|
| 36 |
print('alias.js...'); |
| 37 |
|
| 38 |
for(var i = 0; i < BUNDLES.length; i++){ |
| 39 |
var regExp = new RegExp('\/' + BUNDLES[i] + '\.js$'); |
| 40 |
var fileList = fileUtil.getFilteredFileList(dir, regExp, true); |
| 41 |
|
| 42 |
for(var j = 0; j < fileList.length; j++){ |
| 43 |
var jsFileName = new String(fileList[j]); |
| 44 |
var jsFilePath = jsFileName.split("/"); |
| 45 |
var locale = jsFilePath[jsFilePath.length-2]; |
| 46 |
if(locale=="nls"){continue;} |
| 47 |
try{ |
| 48 |
|
| 49 |
var bundle = dojo.i18n.getLocalization('dojo.cldr', BUNDLES[i], locale); |
| 50 |
var nativeSrcBundle = getNativeBundle(jsFileName); |
| 51 |
}catch(e){} |
| 52 |
|
| 53 |
if(!bundle) continue; |
| 54 |
|
| 55 |
updated = false; |
| 56 |
|
| 57 |
|
| 58 |
_calculateAliasPath(bundle, BUNDLES[i]); |
| 59 |
|
| 60 |
|
| 61 |
_processLocaleAlias(localeAliasPaths, bundle, nativeSrcBundle,locale); |
| 62 |
|
| 63 |
if(updated){ |
| 64 |
fileUtil.saveUtf8File(jsFileName, "(" + dojo.toJson(nativeSrcBundle, true) + ")"); |
| 65 |
} |
| 66 |
|
| 67 |
} |
| 68 |
cleanLocaleAlias(fileList); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
function _calculateAliasPath(bundle, name){ |
| 76 |
for(p in bundle){ |
| 77 |
var index = p.indexOf(LOCALE_ALIAS_MARK); |
| 78 |
if(index >= 0 ){ |
| 79 |
var localeAliasSource = p.substring(0,index); |
| 80 |
if(records[localeAliasSource]){ |
| 81 |
|
| 82 |
continue; |
| 83 |
} |
| 84 |
|
| 85 |
var path = []; |
| 86 |
var aliasIndex = new Number(p.substring(index + LOCALE_ALIAS_MARK.length)); |
| 87 |
|
| 88 |
var i = aliasIndex; |
| 89 |
while(bundle[localeAliasSource + LOCALE_ALIAS_MARK + (--i)]){} |
| 90 |
|
| 91 |
var src = localeAliasSource; |
| 92 |
while(bundle[localeAliasSource + LOCALE_ALIAS_MARK + (++i)]){ |
| 93 |
var mapping = {}; |
| 94 |
mapping[LOCALE_ALIAS_SOURCE_PROPERTY] = src; |
| 95 |
mapping[LOCALE_ALIAS_TARGET_PROPERTY] = bundle[localeAliasSource + LOCALE_ALIAS_MARK + i][LOCALE_ALIAS_TARGET_PROPERTY]; |
| 96 |
mapping[LOCALE_ALIAS_TARGET_BUNDLE] = bundle[localeAliasSource + LOCALE_ALIAS_MARK + i][LOCALE_ALIAS_TARGET_BUNDLE]; |
| 97 |
if (!mapping[LOCALE_ALIAS_TARGET_BUNDLE]) { |
| 98 |
|
| 99 |
continue; |
| 100 |
} |
| 101 |
|
| 102 |
mapping.inSelf = mapping[LOCALE_ALIAS_TARGET_BUNDLE] === name; |
| 103 |
path.push(mapping); |
| 104 |
records[src] = true; |
| 105 |
src = bundle[localeAliasSource + LOCALE_ALIAS_MARK + i][LOCALE_ALIAS_TARGET_PROPERTY]; |
| 106 |
} |
| 107 |
path = path.reverse(); |
| 108 |
|
| 109 |
localeAliasPaths.push(path); |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
function _processLocaleAlias(localeAliasPaths, bundle, nativeSrcBundle,locale){ |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
var processed = {}; |
| 124 |
for(var i = 0; i < localeAliasPaths.length; i++){ |
| 125 |
var path = localeAliasPaths[i]; |
| 126 |
for(var j = 0; j < path.length; j++){ |
| 127 |
var mapping = path[j]; |
| 128 |
if(mapping.inSelf && mapping[LOCALE_ALIAS_SOURCE_PROPERTY] != mapping[LOCALE_ALIAS_TARGET_PROPERTY] |
| 129 |
&& bundle[mapping[LOCALE_ALIAS_TARGET_PROPERTY]]){ |
| 130 |
|
| 131 |
|
| 132 |
if(processed[mapping[LOCALE_ALIAS_SOURCE_PROPERTY]]){ |
| 133 |
|
| 134 |
continue; |
| 135 |
} |
| 136 |
_updateLocaleAlias(bundle, mapping[LOCALE_ALIAS_SOURCE_PROPERTY], bundle, |
| 137 |
mapping[LOCALE_ALIAS_TARGET_PROPERTY], nativeSrcBundle); |
| 138 |
processed[mapping[LOCALE_ALIAS_SOURCE_PROPERTY]] = true; |
| 139 |
}else if(!mapping.inSelf){ |
| 140 |
|
| 141 |
|
| 142 |
var targetBundle = dojo.i18n.getLocalization('dojo.cldr', mapping[LOCALE_ALIAS_TARGET_BUNDLE], locale); |
| 143 |
if(processed[mapping[LOCALE_ALIAS_SOURCE_PROPERTY]]){ |
| 144 |
continue; |
| 145 |
} |
| 146 |
_updateNoneGregAlias(bundle, mapping[LOCALE_ALIAS_SOURCE_PROPERTY], targetBundle, |
| 147 |
mapping[LOCALE_ALIAS_TARGET_PROPERTY], nativeSrcBundle); |
| 148 |
processed[mapping[LOCALE_ALIAS_SOURCE_PROPERTY]] = true; |
| 149 |
} |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
function _updateNoneGregAlias(sourceBundle, aliasSource, targetBundle, aliasTarget, nativeSrcBundle){ |
| 167 |
for (var sKey in sourceBundle) { |
| 168 |
var target = targetBundle[sKey], |
| 169 |
source = sourceBundle[sKey], |
| 170 |
nativeSrc = nativeSrcBundle[sKey]; |
| 171 |
|
| 172 |
if (sKey.indexOf(aliasSource) == 0 && !nativeSrc && target && !compare(source, target)) { |
| 173 |
nativeSrcBundle[sKey] = target; |
| 174 |
sourceBundle[sKey] = target; |
| 175 |
updated = true; |
| 176 |
} else { |
| 177 |
if (sKey.indexOf(aliasSource) == 0 && nativeSrc && dojo.isArray(source) && dojo.isArray(target)) { |
| 178 |
for (var i = 0; i < source.length; i++) { |
| 179 |
if (source[i] === undefined) { |
| 180 |
source[i] = target[i]; |
| 181 |
updated = true; |
| 182 |
} |
| 183 |
} |
| 184 |
if (source.length < target.length) { |
| 185 |
source = sourceBundle[sKey] = source.concat(target.slice(source.length)); |
| 186 |
updated = true; |
| 187 |
} |
| 188 |
if (updated) { |
| 189 |
nativeSrcBundle[sKey] = source; |
| 190 |
} |
| 191 |
} |
| 192 |
} |
| 193 |
} |
| 194 |
} |
| 195 |
function _updateLocaleAlias(sourceBundle,aliasSource, targetBundle, |
| 196 |
aliasTarget, nativeSrcBundle){ |
| 197 |
|
| 198 |
if(!nativeSrcBundle[aliasSource] && nativeSrcBundle[aliasTarget] |
| 199 |
&& !compare(sourceBundle[aliasSource], targetBundle[aliasTarget])){ |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
nativeSrcBundle[aliasSource] = targetBundle[aliasTarget]; |
| 204 |
sourceBundle[aliasSource] = nativeSrcBundle[aliasSource]; |
| 205 |
updated = true; |
| 206 |
}else if(nativeSrcBundle[aliasSource] && dojo.isArray(sourceBundle[aliasSource]) |
| 207 |
&& dojo.isArray(targetBundle[aliasTarget])){ |
| 208 |
if(sourceBundle[aliasSource].length > targetBundle[aliasTarget].length){ |
| 209 |
|
| 210 |
} |
| 211 |
|
| 212 |
for(var i = 0; i < sourceBundle[aliasSource].length; i++){ |
| 213 |
if(sourceBundle[aliasSource][i] == undefined){ |
| 214 |
|
| 215 |
sourceBundle[aliasSource][i] = targetBundle[aliasTarget][i]; |
| 216 |
updated = true; |
| 217 |
} |
| 218 |
} |
| 219 |
if(sourceBundle[aliasSource].length < targetBundle[aliasTarget].length){ |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
sourceBundle[aliasSource] = sourceBundle[aliasSource].concat( |
| 224 |
targetBundle[aliasTarget].slice(sourceBundle[aliasSource].length)); |
| 225 |
updated = true; |
| 226 |
} |
| 227 |
if(updated){ |
| 228 |
nativeSrcBundle[aliasSource] = sourceBundle[aliasSource]; |
| 229 |
} |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
function cleanLocaleAlias(fileList){ |
| 234 |
for(var i = 0; i < fileList.length; i++){ |
| 235 |
var fileName = new String(fileList[i]); |
| 236 |
try{ |
| 237 |
var bundle = getNativeBundle(fileName); |
| 238 |
}catch(e){print(e);} |
| 239 |
|
| 240 |
var newBundle = {}; |
| 241 |
var needUpdate = false; |
| 242 |
for(p in bundle){ |
| 243 |
if(p.indexOf(LOCALE_ALIAS_MARK) < 0){ |
| 244 |
newBundle[p] = bundle[p]; |
| 245 |
}else{ |
| 246 |
needUpdate = true; |
| 247 |
} |
| 248 |
} |
| 249 |
if(needUpdate){ |
| 250 |
fileUtil.saveUtf8File(fileName, "(" + dojo.toJson(newBundle, true) + ")"); |
| 251 |
|
| 252 |
} |
| 253 |
} |
| 254 |
} |