list web directories with javascript
<p>I have the following language selector widget on my site:</p>

<pre><code>jQuery(function($) {

  var setLng = $.url().param('setLng');
  var setLngCookie = $.cookie('i18next');
    var language;

  if (setLngCookie) {
        language = setLngCookie;
  }
  else {
        if (setLng) {
            language_complete = setLng.split("-");
        } else {
            language_complete = navigator.language.split("-");
        }

        language = (language_complete[0]);
  }

  //Build the language selector.
    $.getJSON("../locales/config.json", function(objData) {
      var arrHtml = [];
        var strClass;

      $.each(objData, function(strKey, objLanguage) {
            strClass = (language == objLanguage.locale) ? " class=\"selected-language\"" : ""; //Make sure the language selector has the correct language selected on initial page load.
            arrHtml.push("&lt;a id=\"lang-" + objLanguage.locale + "\" data-i18n=\"language." + objLanguage.locale + "\"" + strClass + "&gt;&lt;/a&gt;");
      });

      $("&lt;div/&gt;", {
            'class': 'language-list',
            html: arrHtml.join('')
      }).appendTo('#language-menu');

        $("li.language-menu").live("click", function(){
            $("#language-menu").toggle();
        });
    });

  function setLanguage() {
    // save to use translation function as resources are fetched
    $(".tzm-i18n").i18n();
    $(".page-i18n").i18n();
    $(".menu").i18n();
    $(".user-menu").i18n();
    $(".search-form").i18n();
    $(".footer-i18n").i18n();

        $("#language-menu").hide();
  }

  i18n.init({
    lng: language,
    debug: true
  }, setLanguage);

  // language selector
  $("#language-menu a").live("click", function() {
    var booReload = false; // TRUE = reload the page; FALSE = do not reload the page
        var $this = $(this);
    var value = $this.attr("id");
    var arrValueParts = value.split("-");
    var language = arrValueParts[1];

    if (booReload) {
      window.location.href = "/index.html?setLng=" + language;
    } else {
      i18n.init({
        lng: language,
        debug: true
      }, setLanguage);
    }

        $("#language-menu a").removeClass("selected-language");
        $this.addClass("selected-language");
  });

});
</code></pre>

<p>and</p>

<pre><code>(zmgc)☺  tree -L 2 locales 
locales
├── README.md
├── config.json
├── de
│   └── translation.json
├── dev
│   └── translation.json
├── en
│   └── translation.json
├── fr
│   └── translation.json
├── jp
│   └── translation.json
├── pt
│   └── translation.json
├── rs
│   └── translation.json
├── ru
│   └── translation.json
└── us
    └── translation.json
</code></pre>

<p>so every time i add a directory in the locals/xx, where xx is the country code from IETF language tag, i have to update the the ../locales/config.json manually!</p>

<p>locals/config.json</p>

<pre><code>{
    "de": {
        "locale": "de",
        "code": "de-DE"
    },
    "en": {
        "locale": "en",
        "code": "en-UK"
    },
    "fr": {
        "locale": "fr",
        "code": "fr-FR"
    },
    "jp": {
        "locale": "jp",
        "code": "jp-JP"
    },
    "pt": {
        "locale": "pt",
        "code": "pt-BR"
    },
    "rs": {
        "locale": "rs",
        "code": "rs-RS"
    },
    "ru": {
        "locale": "ru",
        "code": "ru-RU"
    },
    "us": {
        "locale": "us",
        "code": "en-US"
    }
}
</code></pre>

<p>example locals/en/translation.json</p>

<pre><code>{
  "locale": "en"
  ,"code": "en-UK"
  ,"tzm": "Chapters - Zeitgeist Movement"
  ,"menu": {
    "projects": "Projects"
    ,"map": "Map"
    ,"calendar": "Calendar"
    ,"forums": "Forums"
    ,"more": "More »"
  }
  ,"search": {
    "advanced": "Advanced"
    ,"search": "Search"
  }
  ,"user": {
    "gravatar": "Gravatar"
    ,"profile": "Profile"
    ,"login": "Login"
    ,"log-out": "Log out"
    ,"contact": "Contact"
    ,"help": "Help"
  }
  ,"footer": {
    "zeitgeist": "Zeitgeist"
  }
}
</code></pre>

<p>is there a way to build this by traversing the locals/ directory and building the available languages and excluding the locals/dev from the list of available languages?</p>
