


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, brackets, $, require, Mustache, navigator  */


require.config({
    paths: {
        "text" : "lib/text",
        "i18n" : "lib/i18n"
    },
    locale: brackets.getLocale()
});

define(function (require, exports, module) {
    "use strict";
    
    // Brackets modules
    var CommandManager      = brackets.getModule("command/CommandManager"),
        Menus               = brackets.getModule("command/Menus"),
        Dialogs             = brackets.getModule("widgets/Dialogs");

    // Load an html fragment using the require text plugin. Mustache will later
    // be used to localize some of the text
    var browserWrapperHtml  = require("text!htmlContent/sampleHTMLFragment.html");
    
    // Load the string module for this plugin. Not this references to the strings.js
    // file next to the main.js fiel for this plugin. To access core brackets strings
    // you would call brackets.getModule("strings") instead of require("strings")
    var Strings             = require("strings");


    // This sample command first shows an alert passing in a localized
    // string in JavaScript then it shows a localized HTML dialog.
    function testCommand() {
        alert(Strings.ALERT_MESSAGE);

        Dialogs.showModalDialog("sample-localized-dialog");
    }


    // Register the command
    // A localized command name is used by passing in Strings.COMMAND_NAME
    var myCommandID = "localizationExample.command";
    var command = CommandManager.register(Strings.COMMAND_NAME, myCommandID, testCommand);

    var menu = Menus.getMenu(Menus.AppMenuBar.EDIT_MENU);
    menu.addMenuItem(myCommandID, null, Menus.AFTER, myCommandID);
   
    // Localize the dialog using Strings as the datasource and insert it into the DOM
    var localizedHTML = $(Mustache.render(browserWrapperHtml, Strings));
    $('body').append(localizedHTML);
});
