diff --git a/.gitmodules b/.gitmodules index 9c97798c22a..0716ef81311 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "src/thirdparty/smart-auto-complete"] path = src/thirdparty/smart-auto-complete url = https://github.com/laktek/jQuery-Smart-Auto-Complete.git +[submodule "src/thirdparty/mustache"] + path = src/thirdparty/mustache + url = https://github.com/janl/mustache.js.git diff --git a/src/brackets.js b/src/brackets.js index 547c26dde66..f5c0d66bfe3 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -23,12 +23,15 @@ /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ -/*global require, define, brackets: true, $, PathUtils, window, navigator */ +/*global require, define, brackets: true, $, PathUtils, window, navigator, Mustache */ require.config({ paths: { - "text" : "thirdparty/text" - } + "text" : "thirdparty/text", + "i18n" : "thirdparty/i18n" + }, + // store the locale in localStorage until CEF sets the correct navigator.language + locale: window.localStorage.getItem("locale") }); /** @@ -40,6 +43,10 @@ require.config({ * * Unlike other modules, this one can be accessed without an explicit require() because it exposes * a global object, window.brackets. + * + * Events: + * htmlContentLoadComplete - sent when the HTML DOM is fully loaded. Modules should not touch + * or modify DOM elements before this event is sent. */ define(function (require, exports, module) { "use strict"; @@ -74,6 +81,7 @@ define(function (require, exports, module) { QuickOpen = require("search/QuickOpen"), Menus = require("command/Menus"), FileUtils = require("file/FileUtils"), + MainViewHTML = require("text!htmlContent/main-view.html"), Strings = require("strings"), Dialogs = require("widgets/Dialogs"), ExtensionLoader = require("utils/ExtensionLoader"), @@ -333,6 +341,13 @@ define(function (require, exports, module) { // Main Brackets initialization _initGlobalBrackets(); + + // Localize MainViewHTML and inject into tag + $('body').html(Mustache.render(MainViewHTML, Strings)); + // modules that depend on the HTML DOM should listen to + // the htmlContentLoadComplete event. + $(brackets).trigger("htmlContentLoadComplete"); + $(window.document).ready(_onReady); }); diff --git a/src/command/Commands.js b/src/command/Commands.js index 37c99df7035..fab6e011b40 100644 --- a/src/command/Commands.js +++ b/src/command/Commands.js @@ -88,6 +88,7 @@ define(function (require, exports, module) { exports.DEBUG_RUN_UNIT_TESTS = "debug.runUnitTests"; exports.DEBUG_SHOW_PERF_DATA = "debug.showPerfData"; exports.DEBUG_NEW_BRACKETS_WINDOW = "debug.newBracketsWindow"; + exports.DEBUG_SWITCH_LANGUAGE = "debug.switchLanguage"; // Command that does nothing. Can be used for place holder menuItems diff --git a/src/command/Menus.js b/src/command/Menus.js index 3e1040003ac..6674b895b53 100644 --- a/src/command/Menus.js +++ b/src/command/Menus.js @@ -927,6 +927,8 @@ define(function (require, exports, module) { {key: "Cmd-R", platform: "mac"}]); menu.addMenuItem(Commands.DEBUG_NEW_BRACKETS_WINDOW); menu.addMenuDivider(); + menu.addMenuItem(Commands.DEBUG_SWITCH_LANGUAGE); + menu.addMenuDivider(); menu.addMenuItem(Commands.DEBUG_RUN_UNIT_TESTS); menu.addMenuItem(Commands.DEBUG_SHOW_PERF_DATA); diff --git a/src/debug/DebugCommandHandlers.js b/src/debug/DebugCommandHandlers.js index 6cdcbf61c8a..824ae9d96ff 100644 --- a/src/debug/DebugCommandHandlers.js +++ b/src/debug/DebugCommandHandlers.js @@ -33,7 +33,9 @@ define(function (require, exports, module) { Editor = require("editor/Editor").Editor, Strings = require("strings"), PerfUtils = require("utils/PerfUtils"), - NativeApp = require("utils/NativeApp"); + NativeApp = require("utils/NativeApp"), + NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem, + FileUtils = require("file/FileUtils"); function handleShowDeveloperTools(commandData) { brackets.app.showDeveloperTools(); @@ -130,6 +132,93 @@ define(function (require, exports, module) { function _handleNewBracketsWindow() { window.open(window.location.href); } + + function _handleSwitchLanguage() { + var stringsPath = FileUtils.getNativeBracketsDirectoryPath() + "/nls"; + NativeFileSystem.requestNativeFileSystem(stringsPath, function (dirEntry) { + dirEntry.createReader().readEntries(function (entries) { + + var $activeLanguage; + var $submit; + function setLanguage(event) { + if ($activeLanguage) { + $activeLanguage.css("font-weight", "normal"); + } + $activeLanguage = $(event.currentTarget); + $activeLanguage.css("font-weight", "bold"); + $submit.attr("disabled", false); + } + + var $modal = $("