<commit_before>/*!
 * Strong i18n for express - API
 * Copyright(c) 2011 <NAME>
 * MIT Licensed
 */

 /* 
    You use keys to access translations.
    Keys are prefixed by their view's path (dot-separated).
    Globally available keys have no view path.
    Each language has a tree of view paths with their own key, value pairs at the leaves.
 */

/**
 * Module dependencies.
 */

/**
 * Expose `StrongAPI`.
 */

exports = module.exports = StrongAPI;

/**
 * API proto.
 */

var api = StrongAPI.prototype;

/**
 * Initialize a new `StrongAPI` with an optional `backend`.
 *
 * @param {Object} obj
 * @return {StrongAPI}
 * @api public
 */

function StrongAPI(backend){
  this.init(backend);
};

/**
 * Initialize the api using the provided backend implementation.
 *
 * @param {Object} backend
 * @api private
 */

api.init = function(backend){
  var self = this;

  // The default locale has a default value of 'en'.
  this._default_locale = 'en';

  // Create a virtual property for `default_locale` which allows
  // the value to be conveniently set and retrieved.
  this.__defineGetter__('default_locale', function() {
    return self._default_locale;
  });
  this.__defineSetter__('default_locale', function(new_default_locale) {
    self._default_locale = new_default_locale;
  });

  // Create a virtual property for `locale` which will return the most
  // recent value of `default_locale` until `locale` is specifically set.
  this._locale = undefined;
  this.__defineGetter__('locale', function() {
    return (typeof self._locale === "undefined" || self._locale === null) ? self._default_locale : self._locale;
  });
  this.__defineSetter__('locale', function(new_locale) {
    self._locale = new_locale;
  });

};

/**
 * Retrieve the string associated with the given key in the effective locale.
 *
 * @param {String} key
 * @param {Object} options
 * @return {String} value for that key in the appropriate locale
 * @api public
 */

api.translate = function(key, options) {
  var locale = this.effective_locale(options);
  return "I am a translated string for locale: " + locale;
};


/**
 * Determine the effective locale for this request.
 * The locale can be specified either globally by setting `api.default_locale`, by
 * setting `api.locale`, or by setting the `locale` property on the 
 * `options` object passed into this method.
 *
 * @param {Object} options
 * @api private
 */

api.effective_locale = function(options) {
  // Provide an empty options object if none was given.
  if (options == null) options = {};

  var locale = options["locale"];
  if (typeof locale === "undefined" || locale === null) locale = this.locale;
  
  return locale;
};
<commit_msg>Add some more explicit documentation<commit_after>/*!
 * Strong i18n for express - API
 * Copyright(c) 2011 <NAME>
 * MIT Licensed
 */

 /* 
    You use keys to access translations.
    Keys are prefixed by their view's path (dot-separated).
    Globally available keys have no view path.
    Each language has a tree of view paths with their own key, value pairs at the leaves.
 */

/**
 * Module dependencies.
 */

/**
 * Expose `StrongAPI`.
 */

exports = module.exports = StrongAPI;

/**
 * API proto.
 */

var api = StrongAPI.prototype;

/**
 * Initialize a new `StrongAPI` with an optional `backend`.
 *
 * @param {Object} obj
 * @return {StrongAPI}
 * @api public
 */

function StrongAPI(backend){
  this.init(backend);
};

/**
 * Initialize the api using the provided backend implementation.
 *
 * @param {Object} backend
 * @api private
 */

api.init = function(backend){
  var self = this;

  // The default locale has a default value of 'en'.
  this._default_locale = 'en';

  // Create a virtual property for `default_locale` which allows
  // the value to be conveniently set and retrieved.
  this.__defineGetter__('default_locale', function() {
    return self._default_locale;
  });
  this.__defineSetter__('default_locale', function(new_default_locale) {
    self._default_locale = new_default_locale;
  });

  // Create a virtual property for `locale` which will return the most
  // recent value of `default_locale` until `locale` is specifically set.
  this._locale = undefined;
  this.__defineGetter__('locale', function() {
    return (typeof self._locale === "undefined" || self._locale === null) ? self._default_locale : self._locale;
  });
  this.__defineSetter__('locale', function(new_locale) {
    self._locale = new_locale;
  });

};

/**
 * Retrieve the string associated with the given key in the effective locale.
 *
 * @param {String} key
 * @param {Object} options
 * @return {String} value for that key in the appropriate locale
 * @api public
 */

api.translate = function(key, options) {
  // Provide an empty options object if none was given.
  if (options == null) options = {};

  var locale = this.effective_locale(options);
  return "I am a translated string for locale: " + locale;
};


/**
 * Determine the effective locale for this request.
 * The locale can be specified either globally by setting `api.default_locale`, by
 * setting `api.locale`, or by setting the `locale` property on the 
 * `options` object passed into this method.
 *
 * @param {Object} options
 * @api private
 */

api.effective_locale = function(options) {
  var locale = undefined;
  
  // Use the locale from the provided options (if a valid object) as our first choice.
  if (typeof options !== "undefined" && options !== null) locale = options["locale"];

  // If that didn't work, then ask for the current locale and trust that 
  // we'll get back either the explicitly defined locale or the default_locale.
  if (typeof locale === "undefined" || locale === null) locale = this.locale;
  
  return locale;
};

{'fraction_non_alphanumeric': 0.11831527437958755, 'fraction_numerical': 0.0020971688220901784, 'mean_word_length': 3.5637958532695375, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1256463', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1602, 'n_words': 611}