<commit_before>define(function (require, exports, module) {
  'use strict';

  var L20n = require('../l20n');
  var io = require('./platform/io');
  var Parser = require('./parser').Parser;
  var Locale = require('./context').Locale;
  var Resource = require('./context').Resource;
  var Compiler = require('./compiler').Compiler;

  var rtlLocales = ['ar', 'fa', 'he', 'ps', 'ur'];

  var resLinks = null;

  var locales = {};
  var curLocale = null;

  webL10nBridge();

  function setLocale(lang) {
    curLocale = lang;
    if (!resLinks) {
      indexResources(document, createLocale);
    } else {
      createLocale();
    }
  }

  function createLocale() {

    var parser = new Parser();
    var compiler = new Compiler();
    var locale = new Locale(curLocale, parser, compiler);

    resLinks[curLocale].forEach(function(res) {
      var resource = new Resource(res, parser);
      locale.resources.push(resource); 
    });

    locale.build();

    locales[curLocale] = locale;
    fireLocalizedEvent();
  }


  function webL10nBridge() {
    if (!navigator.mozL10n) {
      navigator.mozL10n = {
        get: function(id) {
          var entry = locales[curLocale].getEntry(id);
          if (!entry) {
            return null;
          }
          return entry.get().value;
        },
        localize: function() {},
        language: {
          get code() { return curLocale },
          set code(lang) {
            setLocale(lang);
          },
          get direction() {
            // getting direction is the only way in BTO that we know
            // that we work on the default locale
            translateDocument();
            return (rtlLocales.indexOf(curLocale) >= 0) ? 'rtl' : 'ltr';
          },
        },
        getDictionary: getSubDictionary,
        ready: function() {},
      };
    }
  }

  function indexResources(doc, cb) {
    resLinks = {};<commit_msg>add args support to API/compiler<commit_after>define(function (require, exports, module) {
  'use strict';

  var L20n = require('../l20n');
  var io = require('./platform/io');
  var Parser = require('./parser').Parser;
  var Locale = require('./context').Locale;
  var Resource = require('./context').Resource;
  var Compiler = require('./compiler').Compiler;

  var rtlLocales = ['ar', 'fa', 'he', 'ps', 'ur'];

  var resLinks = null;

  var locales = {};
  var curLocale = null;

  webL10nBridge();

  function setLocale(lang) {
    curLocale = lang;
    if (!resLinks) {
      indexResources(document, createLocale);
    } else {
      createLocale();
    }
  }

  function createLocale() {

    var parser = new Parser();
    var compiler = new Compiler();
    var locale = new Locale(curLocale, parser, compiler);

    resLinks[curLocale].forEach(function(res) {
      var resource = new Resource(res, parser);
      locale.resources.push(resource); 
    });

    locale.build();

    locales[curLocale] = locale;
    fireLocalizedEvent();
  }


  function webL10nBridge() {
    if (!navigator.mozL10n) {
      navigator.mozL10n = {
        get: function(id, args) {
          // it would be better to use context here
          // to deal with fallbacks and imitate client side l10n 
          var entry = locales[curLocale].getEntry(id);
          if (!entry) {
            return null;
          }
          var val = entry.get(args);
          return val.value;
        },
        localize: function() {},
        language: {
          get code() { return curLocale },
          set code(lang) {
            setLocale(lang);
          },
          get direction() {
            // getting direction is the only way in BTO that we know
            // that we work on the default locale
            translateDocument();
            return (rtlLocales.indexOf(curLocale) >= 0) ? 'rtl' : 'ltr';
          },
        },
        getDictionary: getSubDictionary,
        ready: function() {},
      };
    }
  }

  function indexResources(doc, cb) {
    resLinks = {};
{'fraction_non_alphanumeric': 0.13695871097683787, 'fraction_numerical': 0.007049345417925478, 'mean_word_length': 2.17585931254996, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5736321', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1134, 'n_words': 299}