satyr (owner)

Revisions

gist: 167318 Download_button fork
public
Public Clone URL: git://gist.github.com/167318.git
Embed All Files: show embed
locale-tools.ubiq.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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: 'murky.satyr@gmail.com'},
  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)) });
}