Skip to content

Instantly share code, notes, and snippets.

@satyr
Created August 13, 2009 17:32
Show Gist options
  • Save satyr/167318 to your computer and use it in GitHub Desktop.
Save satyr/167318 to your computer and use it in GitHub Desktop.
const BZ = 'http://www.babelzilla.org';
const PLocale = 'general.useragent.locale';
CmdUtils.CreateCommand({
name: 'change locale',
icon: 'chrome://ubiquity/skin/icons/favicon.ico',
author: {name: 'satyr', email: '[email protected]'},
license: 'MIT',
description: 'Changes your Firefox locale.',
argument: CmdUtils.NounType('locale', <![CDATA[
af ar as be bg bn-BD bn-IN ca cs cy da de el en-GB en-US eo es-AR es-CL
es-ES es-MX et eu fa fi fr fy-NL ga-IE gl gu-IN he hi-IN hr hu i is it ja
ja-JP-mac ka kk kn ko ku lt lv mk ml mn mr ms nb-NO nl nn-NO oc or pa-IN pl
pt-BR pt-PT rm ro ru si sk sl sq sr sv-SE ta ta-LK te th tr uk vi
zh-CN zh-TW]]>.match(/\S+/g), '^en-US$'),
execute: function cloc_execute({object: {text}}){
Application.prefs.setValue(PLocale, text);
displayMessage(text, this);
},
preview: function cloc_preview(pb, {object: {text}}){
pb.innerHTML = (Application.prefs.getValue(PLocale, 'en-US') +
' \u2192 ' + text);
},
});
function cmd_extract_empty_locales(){
l10nRows(function($rows){
displayMessage(CmdUtils.copyToClipboard(
$rows.map(function()(
let(tds = this.getElementsByTagName('td'))(
/^\s*0\s*0%/(tds[2].textContent) && tds[1].textContent)))
.get().join(' ')));
});
}
function cmd_extract_translators(){
l10nRows(function($rows){
var done = 0;
($rows.map(function()(
let(tds = this.getElementsByTagName('td'))(
/^(?!\s*0\s*0%)/(tds[2].textContent) &&
let(code = tds[1].textContent.trim())(
/^(?!en-US)/(code) &&
{ href: tds[0].getElementsByTagName('a')[0].href,
code: code }))))
.get().some(function({href, code}, i, arr){
$.get(BZ + href, function(h){
arr[i] = (
[a.textContent.trim()
for each(a in $('#localized > table a', h).get())].join(', ') +
' ('+ code +')');
if(++done === arr.length)
displayMessage(CmdUtils.copyToClipboard(
[(<em>{s}</em>).toXMLString().replace(/>/g, ':translator>')
for each(s in arr)].join('\n')));
});
}));
});
}
function l10nRows(cb){
$.post((BZ +'/index2.php'+
'?option=com_wts&type=ajax&task=loadlist'),
{Itemid: 203, extension: 5165, no_html: 1},
function(htm){ cb($('tbody > tr', htm)) });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment