Skip to content

Commit 742b92b

Browse files
committed
login: Add translations
1 parent 9e63c58 commit 742b92b

File tree

2 files changed

+92
-15
lines changed

2 files changed

+92
-15
lines changed

assets/l10n/app_en.arb

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,25 @@
5959
"@errorCopyingFailed": {
6060
"description": "Error message when copying the text of a message to the users system clipboard failed."
6161
},
62+
"errorLoginInvalidInputTitle": "Invalid input",
63+
"@errorLoginInvalidInputTitle": {
64+
"description": "Error title for login when input is invalid."
65+
},
66+
"errorLoginFailed": "Login failed",
67+
"@errorLoginFailed": {
68+
"description": "Error title for login when signing into a Zulip server fails."
69+
},
70+
"errorLoginCouldNotConnect": "Failed to connect to server:\n{url}",
71+
"@errorLoginCouldNotConnect": {
72+
"description": "Error message when the app could not connect to the server.",
73+
"placeholders": {
74+
"url": {"type": "String", "example": "http://example.com/"}
75+
}
76+
},
77+
"errorLoginCouldNotConnectTitle": "Could not connect",
78+
"@errorLoginCouldNotConnectTitle": {
79+
"description": "Error title when the app could not connect to the server."
80+
},
6281
"errorMessageDoesNotSeemToExist": "That message does not seem to exist.",
6382
"@errorMessageDoesNotSeemToExist": {
6483
"description": "Error message when loading a message that does not exist."
@@ -67,6 +86,13 @@
6786
"@errorQuotationFailed": {
6887
"description": "Error message when quoting a message failed."
6988
},
89+
"errorServerMessage": "The server said:\n\n{message}",
90+
"@errorServerMessage": {
91+
"description": "Error message that quotes an error from the server.",
92+
"placeholders": {
93+
"message": {"type": "String", "example": "Invalid format"}
94+
}
95+
},
7096
"successLinkCopied": "Link copied",
7197
"@successLinkCopied": {
7298
"description": "Success message after copy link action completed."
@@ -107,6 +133,50 @@
107133
"@lightboxCopyLinkTooltip": {
108134
"description": "Tooltip in lightbox for the copy link action."
109135
},
136+
"loginPageTitle": "Log in",
137+
"@loginPageTitle": {
138+
"description": "Page title for login page."
139+
},
140+
"loginFormSubmitLabel": "Log in",
141+
"@loginFormSubmitLabel": {
142+
"description": "Button text to submit login credentials."
143+
},
144+
"loginAddAnAccount": "Add an account",
145+
"@loginAddAnAccount": {
146+
"description": "Page title for screen to add a Zulip account."
147+
},
148+
"loginServerUrlInputLabel": "Your Zulip server URL",
149+
"@loginServerUrlInputLabel": {
150+
"description": "Input label in login page for Zulip server URL entry."
151+
},
152+
"loginHidePassword": "Hide password",
153+
"@loginHidePassword": {
154+
"description": "Icon label for button to hide password in input form."
155+
},
156+
"loginEmailLabel": "Email address",
157+
"@loginEmailLabel": {
158+
"description": "Label for input when an email is required to login."
159+
},
160+
"loginErrorMissingEmail": "Please enter your email.",
161+
"@loginErrorMissingEmail": {
162+
"description": "Error message when an empty email was provided."
163+
},
164+
"loginPasswordLabel": "Password",
165+
"@loginPasswordLabel": {
166+
"description": "Label for input for password field."
167+
},
168+
"loginErrorMissingPassword": "Please enter your password.",
169+
"@loginErrorMissingPassword": {
170+
"description": "Error message when an empty password was provided."
171+
},
172+
"loginUsernameLabel": "Username",
173+
"@loginUsernameLabel": {
174+
"description": "Label for input when a username is required to login."
175+
},
176+
"loginErrorMissingUsername": "Please enter your username.",
177+
"@loginErrorMissingUsername": {
178+
"description": "Error message when an empty username was provided."
179+
},
110180
"topicValidationErrorTooLong": "Topic length shouldn't be greater than 60 characters.",
111181
"@topicValidationErrorTooLong": {
112182
"description": "Topic validation error when topic is too long."

lib/widgets/login.dart

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class _AddAccountPageState extends State<AddAccountPage> {
141141
final error = _parseResult.error;
142142
if (error != null) {
143143
showErrorDialog(context: context,
144-
title: 'Invalid input',
144+
title: zulipLocalizations.errorLoginInvalidInputTitle,
145145
message: error.message(zulipLocalizations));
146146
return;
147147
}
@@ -161,7 +161,8 @@ class _AddAccountPageState extends State<AddAccountPage> {
161161
// TODO(#105) give more helpful feedback; see `fetchServerSettings`
162162
// in zulip-mobile's src/message/fetchActions.js.
163163
showErrorDialog(context: context,
164-
title: 'Could not connect', message: 'Failed to connect to server:\n$url');
164+
title: zulipLocalizations.errorLoginCouldNotConnectTitle,
165+
message: zulipLocalizations.errorLoginCouldNotConnect(url.toString()));
165166
return;
166167
}
167168
// https://github.com/dart-lang/linter/issues/4007
@@ -190,7 +191,7 @@ class _AddAccountPageState extends State<AddAccountPage> {
190191
: error.message(zulipLocalizations);
191192

192193
return Scaffold(
193-
appBar: AppBar(title: const Text('Add an account'),
194+
appBar: AppBar(title: Text(zulipLocalizations.loginAddAnAccount),
194195
bottom: _inProgress
195196
? const PreferredSize(preferredSize: Size.fromHeight(4),
196197
child: LinearProgressIndicator(minHeight: 4)) // 4 restates default
@@ -215,7 +216,7 @@ class _AddAccountPageState extends State<AddAccountPage> {
215216
// …but leave out unfocusing the input in case more editing is needed.
216217
},
217218
decoration: InputDecoration(
218-
labelText: 'Your Zulip server URL',
219+
labelText: zulipLocalizations.loginServerUrlInputLabel,
219220
errorText: errorText,
220221
helperText: kLayoutPinningHelperText,
221222
hintText: 'your-org.zulipchat.com')),
@@ -224,7 +225,7 @@ class _AddAccountPageState extends State<AddAccountPage> {
224225
onPressed: !_inProgress && errorText == null
225226
? () => _onSubmitted(context)
226227
: null,
227-
child: const Text('Continue')),
228+
child: Text(zulipLocalizations.dialogContinue)),
228229
])))));
229230
}
230231
}
@@ -293,10 +294,13 @@ class _PasswordLoginPageState extends State<PasswordLoginPage> {
293294
// TODO(#105) give more helpful feedback. The RN app is
294295
// unhelpful here; we should at least recognize invalid auth errors, and
295296
// errors for deactivated user or realm (see zulip-mobile#4571).
297+
final zulipLocalizations = ZulipLocalizations.of(context);
296298
final message = (e is ZulipApiException)
297-
? 'The server said:\n\n${e.message}'
299+
? zulipLocalizations.errorServerMessage(e.message)
298300
: e.message;
299-
showErrorDialog(context: context, title: 'Login failed', message: message);
301+
showErrorDialog(context: context,
302+
title: zulipLocalizations.errorLoginFailed,
303+
message: message);
300304
return;
301305
}
302306

@@ -339,6 +343,7 @@ class _PasswordLoginPageState extends State<PasswordLoginPage> {
339343
@override
340344
Widget build(BuildContext context) {
341345
assert(!PerAccountStoreWidget.debugExistsOf(context));
346+
final zulipLocalizations = ZulipLocalizations.of(context);
342347
final requireEmailFormatUsernames = widget.serverSettings.requireEmailFormatUsernames;
343348

344349
final usernameField = TextFormField(
@@ -354,8 +359,8 @@ class _PasswordLoginPageState extends State<PasswordLoginPage> {
354359
validator: (value) {
355360
if (value == null || value.trim().isEmpty) {
356361
return requireEmailFormatUsernames
357-
? 'Please enter your email.'
358-
: 'Please enter your username.';
362+
? zulipLocalizations.loginErrorMissingEmail
363+
: zulipLocalizations.loginErrorMissingUsername;
359364
}
360365
if (requireEmailFormatUsernames) {
361366
// TODO(#106): validate is in the shape of an email
@@ -364,7 +369,9 @@ class _PasswordLoginPageState extends State<PasswordLoginPage> {
364369
},
365370
textInputAction: TextInputAction.next,
366371
decoration: InputDecoration(
367-
labelText: requireEmailFormatUsernames ? 'Email address' : 'Username',
372+
labelText: requireEmailFormatUsernames
373+
? zulipLocalizations.loginEmailLabel
374+
: zulipLocalizations.loginUsernameLabel,
368375
helperText: kLayoutPinningHelperText,
369376
));
370377

@@ -376,14 +383,14 @@ class _PasswordLoginPageState extends State<PasswordLoginPage> {
376383
autovalidateMode: AutovalidateMode.onUserInteraction,
377384
validator: (value) {
378385
if (value == null || value.isEmpty) {
379-
return 'Please enter your password.';
386+
return zulipLocalizations.loginErrorMissingPassword;
380387
}
381388
return null;
382389
},
383390
textInputAction: TextInputAction.go,
384391
onFieldSubmitted: (value) => _submit(),
385392
decoration: InputDecoration(
386-
labelText: 'Password',
393+
labelText: zulipLocalizations.loginPasswordLabel,
387394
helperText: kLayoutPinningHelperText,
388395
// TODO(material-3): Simplify away `Semantics` by using IconButton's
389396
// M3-only params `isSelected` / `selectedIcon`, after fixing
@@ -393,14 +400,14 @@ class _PasswordLoginPageState extends State<PasswordLoginPage> {
393400
// [ButtonStyleButton].)
394401
suffixIcon: Semantics(toggled: _obscurePassword,
395402
child: IconButton(
396-
tooltip: 'Hide password',
403+
tooltip: zulipLocalizations.loginHidePassword,
397404
onPressed: _handlePasswordVisibilityPress,
398405
icon: _obscurePassword
399406
? const Icon(Icons.visibility_off)
400407
: const Icon(Icons.visibility)))));
401408

402409
return Scaffold(
403-
appBar: AppBar(title: const Text('Log in'),
410+
appBar: AppBar(title: Text(zulipLocalizations.loginPageTitle),
404411
bottom: _inProgress
405412
? const PreferredSize(preferredSize: Size.fromHeight(4),
406413
child: LinearProgressIndicator(minHeight: 4)) // 4 restates default
@@ -420,7 +427,7 @@ class _PasswordLoginPageState extends State<PasswordLoginPage> {
420427
const SizedBox(height: 8),
421428
ElevatedButton(
422429
onPressed: _inProgress ? null : _submit,
423-
child: const Text('Log in')),
430+
child: Text(zulipLocalizations.loginFormSubmitLabel)),
424431
])))))));
425432
}
426433
}

0 commit comments

Comments
 (0)