Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<pre id="output-source" class="output"></pre>
<pre id="output-js" class="output"></pre>
</body>
</html>
 
var url = "https://raw.githubusercontent.com/freifunk-gluon/gluon/master/package/gluon-config-mode-hostname/i18n/de.po"
fetch(url)
  .then(function(res) {
  return res.body.getReader();
})
  .then(function(reader) {
  return reader.read();
})
  .then(function(stream) {
  var decoder = new TextDecoder();
  var body = decoder.decode(stream.value || new Uint8Array);
  return body
})
  .then(function(body) {
  var text = body.replace(/\\n/g, '');
  var lines = text.split('\n');
  console.log(text)
  
  var arr = []
  var obj = {}
  
  for (var i = 0; i < lines.length; i++) {
    // key:value pairs
    if (lines[i].indexOf(':') !== -1) {
      var line = lines[i].replace(/"/g, '');
      var pair = line.split(':');
      if (pair.length) {
        obj[pair[0]] = pair[1].trim();
      }
    }
    // msgid
    if (lines[i].indexOf('msgid') !== -1) {
      var msgobj = {};
      var msgid = lines[i].split(' "')[1].replace(/\"/g, '');
      msgobj.msgid = msgid;
      // msgstr
      if (lines[i+1].indexOf('msgstr') !== -1) {
        var msgstr = lines[i+1].split(' "')[1].replace(/\"/g, '');
        msgobj.msgstr = msgstr;
      }
      arr.push(msgobj);
      
    }
  }
  
  arr.push(obj)
  
  document.getElementById('output-source')
    .innerHTML = body
  
  document.getElementById('output-js')
    .innerHTML = JSON.stringify(arr, null, 2);
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers