Make sure javascript login is internationalized
Make sure javascript login is internationalized

--- a/include/controller/Controller_Login.class.php
+++ b/include/controller/Controller_Login.class.php
@@ -118,7 +118,11 @@
 	{
 		if (!(isset($this->params['output']) && ($this->params['output'] == 'js'))) {
 			if ($this->loginSuccess === false) {
-				$this->tpl->assign('loginerror', 'Invalid username or password');
+				if ($this->resource) {
+					$this->tpl->assign('loginerror', $this->resource->translate('Invalid username or password'));
+				} else {
+					$this->tpl->assign('loginerror', 'Invalid username or password');
+				}
 			}
 			if (!empty($this->params['redirect'])) {
 				$this->tpl->assign('redirect', $this->params['redirect']);
@@ -139,8 +143,13 @@
 				$result['success'] = true;
 			else {
 				$result['success'] = false;
-				if ($this->loginSuccess === false)
-					$result['message'] = 'Invalid username or password';
+				if ($this->loginSuccess === false) {
+					if ($this->resource) {
+						$result['message'] = $this->resource->translate('Invalid username or password');
+					} else {
+						$result['message'] = 'Invalid username or password';
+					}
+				}
 			}
 			echo json_encode($result);
 			return;

--- a/js/modules/loginpopup.js
+++ b/js/modules/loginpopup.js
@@ -7,7 +7,7 @@
  * @subpackage Javascript
  */
 
-define(['jquery', 'modules/geturl', 'qtip'], function($, url) {
+define(['jquery', 'modules/geturl', 'modules/resources', 'qtip'], function($, url, resources) {
   return function(element) {
     $(element).qtip({
       content: {
@@ -22,20 +22,20 @@
           loginForm.append(loginError);
 
           var usernameDiv = $(document.createElement('div')).addClass('field');
-          var usernameLabel = $(document.createElement('label')).attr('for', 'username').text('username:');
+          var usernameLabel = $(document.createElement('label')).attr('for', 'username').text(resources.UsernameLabel);
           var usernameField = $(document.createElement('input')).attr('type', 'text').attr('name', 'username');
           usernameDiv.append(usernameLabel);
           usernameDiv.append(usernameField);
           loginForm.append(usernameDiv);
 
           var passwordDiv = $(document.createElement('div')).addClass('field');
-          var passwordLabel = $(document.createElement('label')).attr('for', 'password').text('password:');
+          var passwordLabel = $(document.createElement('label')).attr('for', 'password').text(resources.PasswordLabel);
           var passwordField = $(document.createElement('input')).attr('type', 'password').attr('name', 'password');
           passwordDiv.append(passwordLabel);
           passwordDiv.append(passwordField);
           loginForm.append(passwordDiv);
 
-          var loginButton = $(document.createElement('input')).attr('type', 'submit').attr('value', 'login');
+          var loginButton = $(document.createElement('input')).attr('type', 'submit').attr('value', resources.Login);
           loginForm.append(loginButton);
 
           loginForm.bind('submit', function(event) {
@@ -43,11 +43,11 @@
             var password = $('input[name=password]', this).val();
             var errorContainer = $('.loginError', this);
             if (!username) {
-              errorContainer.text('Username is required');
+              errorContainer.text(resources.UsernameIsRequired);
               return false;
             }
             if (!password) {
-              errorContainer.text('Password is required');
+              errorContainer.text(resources.PasswordIsRequired);
               return false;
             }
             var inputs = $('input', this);
@@ -68,14 +68,14 @@
                   } else if (data.message) {
                     errorContainer.text(data.message);
                   } else {
-                    errorContainer.text('Error while logging in');
+                    errorContainer.text(resources.AnErrorOccurredWhileLoggingIn);
                   }
                 } else {
-                  errorContainer.text('Error while logging in');
+                  errorContainer.text(resources.AnErrorOccurredWhileLoggingIn);
                 }
               },
               error: function(jqXHR, message) {
-                  errorContainer.text('Error while logging in');
+                  errorContainer.text(resources.AnErrorOccurredWhileLoggingIn);
               },
               beforeSend: function() {
                 inputs.attr('disabled', 'disabled');
@@ -91,7 +91,7 @@
           return container;
         },
         title: {
-          text: 'Login',
+          text: resources.LoginTitle,
           button: true
         }
       },

--- a/locale/gitphp.pot
+++ b/locale/gitphp.pot
@@ -8,7 +8,7 @@
 msgstr ""
 "Project-Id-Version: GitPHP 0.2.8\n"
 "Report-Msgid-Bugs-To: xiphux@gmail.com\n"
-"POT-Creation-Date: 2012-10-13 16:53-0500\n"
+"POT-Creation-Date: 2012-10-13 23:16-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -309,7 +309,7 @@
 #: templates/login.tpl
 #: templates/main.tpl
 #: templates/projectbase.tpl
-#: include/controller/ControllerBase.class.php:509
+#: include/controller/ControllerBase.class.php:511
 #: include/controller/Controller_ProjectList.class.php:76
 msgid "projects"
 msgstr ""
@@ -825,11 +825,13 @@
 
 # Label for the username field on the login form
 #: templates/login.tpl
+#: templates/main.tpl
 msgid "username:"
 msgstr ""
 
 # Label for the password field on the login form
 #: templates/login.tpl
+#: templates/main.tpl
 msgid "password:"
 msgstr ""
 
@@ -846,3 +848,31 @@
 msgid "logout %1"
 msgstr ""
 
+# Error message that appears when there is a technical error
+# during login
+#: templates/main.tpl
+msgid "An error occurred while logging in"
+msgstr ""
+
+# Title of the login modal message box
+#: templates/main.tpl
+msgid "Login"
+msgstr ""
+
+# Error message when the username or the password is
+# invalid (login failure)
+#: include/controller/Controller_Login.class.php:122
+#: include/controller/Controller_Login.class.php:148
+msgid "Invalid username or password"
+msgstr ""
+
+# Error message when a username is not entered during login
+#: templates/main.tpl
+msgid "Username is required"
+msgstr ""
+
+# Error message when a password is not entered during login
+#: templates/main.tpl
+msgid "Password is required"
+msgstr ""
+

--- a/templates/main.tpl
+++ b/templates/main.tpl
@@ -70,7 +70,14 @@
 				Loading: "{t escape='js'}Loading…{/t}",
 				LoadingBlameData: "{t escape='js'}Loading blame data…{/t}",
 				Snapshot: "{t escape='js'}snapshot{/t}",
-				NoMatchesFound: '{t escape=no}No matches found for "%1"{/t}'
+				NoMatchesFound: '{t escape=no}No matches found for "%1"{/t}',
+        UsernameLabel: "{t escape='js'}username:{/t}",
+        PasswordLabel: "{t escape='js'}password:{/t}",
+        Login: "{t escape='js'}login{/t}",
+        AnErrorOccurredWhileLoggingIn: "{t escape='js'}An error occurred while logging in{/t}",
+        LoginTitle: "{t escape='js'}Login{/t}",
+        UsernameIsRequired: "{t escape='js'}Username is required{/t}",
+        PasswordIsRequired: "{t escape='js'}Password is required{/t}"
 			}
 		}
 	}

comments