Skip to content

Commit

Permalink
refactor: create i18n package (#29097)
Browse files Browse the repository at this point in the history
Co-authored-by: Guilherme Gazzo <[email protected]>
Co-authored-by: Marcos Spessatto Defendi <[email protected]>
  • Loading branch information
ggazzo and MarcosSpessatto authored May 4, 2023
1 parent 8dbf241 commit fd3532d
Show file tree
Hide file tree
Showing 213 changed files with 7,802 additions and 6,264 deletions.
6 changes: 4 additions & 2 deletions apps/meteor/.meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
rocketchat:ddp
rocketchat:mongo-config
rocketchat:oauth2-server
rocketchat:i18n
rocketchat:[email protected]
rocketchat:restivus
rocketchat:livechat
rocketchat:streamer
Expand Down Expand Up @@ -73,3 +71,7 @@ [email protected]
[email protected]

[email protected]

# photoswipe

jquery
18 changes: 0 additions & 18 deletions apps/meteor/.meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ [email protected]
[email protected]
[email protected]
[email protected]
aldeed:[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
Expand Down Expand Up @@ -45,16 +41,13 @@ [email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
kadira:[email protected]
[email protected]
[email protected]
mdg:[email protected]
[email protected]
[email protected]
[email protected]
Expand All @@ -74,13 +67,11 @@ [email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
ostrio:[email protected]
pauli:[email protected]
pauli:[email protected]
[email protected]
raix:[email protected]
[email protected]
[email protected]
[email protected]
Expand All @@ -89,30 +80,21 @@ [email protected]
[email protected]
[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
simple:[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/2fa/client/TOTPPassword.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';

import { t } from '../../utils/client';
import { t } from '../../utils/lib/i18n';
import { process2faReturn } from '../../../client/lib/2fa/process2faReturn';
import { isTotpInvalidError, reportError } from '../../../client/lib/2fa/utils';
import { dispatchToastMessage } from '../../../client/lib/toast';
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/2fa/client/overrideMeteorCall.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meteor } from 'meteor/meteor';

import { t } from '../../utils/client';
import { t } from '../../utils/lib/i18n';
import { process2faReturn, process2faAsyncReturn } from '../../../client/lib/2fa/process2faReturn';
import { isTotpInvalidError } from '../../../client/lib/2fa/utils';
import { dispatchToastMessage } from '../../../client/lib/toast';
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/2fa/server/code/EmailCheck.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Random } from '@rocket.chat/random';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { Accounts } from 'meteor/accounts-base';
import bcrypt from 'bcrypt';
import type { IUser } from '@rocket.chat/core-typings';
Expand All @@ -8,6 +7,7 @@ import { Users } from '@rocket.chat/models';
import { settings } from '../../../settings/server';
import * as Mailer from '../../../mailer/server/api';
import type { ICodeCheck, IProcessInvalidCodeResult } from './ICodeCheck';
import { i18n } from '../../../../server/lib/i18n';

export class EmailCheck implements ICodeCheck {
public readonly name = 'email';
Expand All @@ -34,7 +34,7 @@ export class EmailCheck implements ICodeCheck {
private async send2FAEmail(address: string, random: string, user: IUser): Promise<void> {
const language = user.language || settings.get('Language') || 'en';

const t = (s: string): string => TAPi18n.__(s, { lng: language });
const t = (s: string): string => i18n.t(s, { lng: language });

await Mailer.send({
to: address,
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/2fa/server/functions/resetTOTP.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Meteor } from 'meteor/meteor';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import type { IUser } from '@rocket.chat/core-typings';
import { Users } from '@rocket.chat/models';

import { settings } from '../../../settings/server';
import * as Mailer from '../../../mailer/server/api';
import { isUserIdFederated } from '../../../../server/lib/isUserIdFederated';
import { i18n } from '../../../../server/lib/i18n';

const sendResetNotification = async function (uid: string): Promise<void> {
const user = await Users.findOneById<Pick<IUser, 'language' | 'emails'>>(uid, {
Expand All @@ -21,7 +21,7 @@ const sendResetNotification = async function (uid: string): Promise<void> {
return;
}

const t = (s: string): string => TAPi18n.__(s, { lng: language });
const t = (s: string): string => i18n.t(s, { lng: language });
const text = `
${t('Your_TOTP_has_been_reset')}
Expand Down
6 changes: 3 additions & 3 deletions apps/meteor/app/api/server/v1/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import crypto from 'crypto';

import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import EJSON from 'ejson';
import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
import { escapeHTML } from '@rocket.chat/string-helpers';
Expand Down Expand Up @@ -30,6 +29,7 @@ import { getLoggedInUser } from '../helpers/getLoggedInUser';
import { getUserInfo } from '../helpers/getUserInfo';
import { getPaginationItems } from '../helpers/getPaginationItems';
import { getUserFromParams } from '../helpers/getUserFromParams';
import { i18n } from '../../../../server/lib/i18n';

/**
* @openapi
Expand Down Expand Up @@ -244,7 +244,7 @@ API.v1.addRoute(
onlineCacheDate = Date.now();
}

text = `${onlineCache} ${TAPi18n.__('Online')}`;
text = `${onlineCache} ${i18n.t('Online')}`;
break;
case 'channel':
if (!channel) {
Expand Down Expand Up @@ -281,7 +281,7 @@ API.v1.addRoute(
}
break;
default:
text = TAPi18n.__('Join_Chat').toUpperCase();
text = i18n.t('Join_Chat').toUpperCase();
}

const iconSize = hideIcon ? 7 : 24;
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/api/server/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import { Match, check } from 'meteor/check';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import type { IExportOperation, ILoginToken, IPersonalAccessToken, IUser, UserStatus } from '@rocket.chat/core-typings';
import { Users, Subscriptions } from '@rocket.chat/models';
import type { Filter } from 'mongodb';
Expand Down Expand Up @@ -45,6 +44,7 @@ import { getUserFromParams } from '../helpers/getUserFromParams';
import { isUserFromParams } from '../helpers/isUserFromParams';
import { saveUserPreferences } from '../../../../server/methods/saveUserPreferences';
import { setUsernameWithValidation } from '../../../lib/server/functions/setUsername';
import { i18n } from '../../../../server/lib/i18n';

API.v1.addRoute(
'users.getAvatar',
Expand Down Expand Up @@ -629,7 +629,7 @@ API.v1.addRoute(
preferences,
});
}
return API.v1.failure(TAPi18n.__('Accounts_Default_User_Preferences_not_available').toUpperCase());
return API.v1.failure(i18n.t('Accounts_Default_User_Preferences_not_available').toUpperCase());
},
},
);
Expand Down
10 changes: 5 additions & 5 deletions apps/meteor/app/authentication/server/startup/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { Match } from 'meteor/check';
import { Accounts } from 'meteor/accounts-base';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import _ from 'underscore';
import { escapeRegExp, escapeHTML } from '@rocket.chat/string-helpers';
import { Roles, Settings, Users } from '@rocket.chat/models';
Expand All @@ -20,6 +19,7 @@ import { safeGetMeteorUser } from '../../../utils/server/functions/safeGetMeteor
import { safeHtmlDots } from '../../../../lib/utils/safeHtmlDots';
import { joinDefaultChannels } from '../../../lib/server/functions/joinDefaultChannels';
import { setAvatarFromServiceWithValidation } from '../../../lib/server/functions/setUserAvatar';
import { i18n } from '../../../../server/lib/i18n';

Accounts.config({
forbidClientAccountCreation: true,
Expand All @@ -37,7 +37,7 @@ Meteor.startup(() => {

Accounts.emailTemplates.userToActivate = {
subject() {
const subject = TAPi18n.__('Accounts_Admin_Email_Approval_Needed_Subject_Default');
const subject = i18n.t('Accounts_Admin_Email_Approval_Needed_Subject_Default');
const siteName = settings.get('Site_Name');

return `[${siteName}] ${subject}`;
Expand All @@ -48,7 +48,7 @@ Accounts.emailTemplates.userToActivate = {
? 'Accounts_Admin_Email_Approval_Needed_With_Reason_Default'
: 'Accounts_Admin_Email_Approval_Needed_Default';

return Mailer.replace(TAPi18n.__(email), {
return Mailer.replace(i18n.t(email), {
name: escapeHTML(options.name),
email: escapeHTML(options.email),
reason: escapeHTML(options.reason),
Expand All @@ -63,14 +63,14 @@ Accounts.emailTemplates.userActivated = {
const subject = `Accounts_Email_${action}_Subject`;
const siteName = settings.get('Site_Name');

return `[${siteName}] ${TAPi18n.__(subject)}`;
return `[${siteName}] ${i18n.t(subject)}`;
},

html({ active, name, username }) {
const activated = username ? 'Activated' : 'Approved';
const action = active ? activated : 'Deactivated';

return Mailer.replace(TAPi18n.__(`Accounts_Email_${action}`), {
return Mailer.replace(i18n.t(`Accounts_Email_${action}`), {
name: escapeHTML(name),
});
},
Expand Down
Loading

0 comments on commit fd3532d

Please sign in to comment.