How to use the t function from i18next

Find comprehensive JavaScript i18next.t code examples handpicked from public code repositorys.

8
9
10
11
12
13
14
15
16
17
validate(val, msg, arg) {
        const lng = msg.client.translator.resolveLanguage(msg);
        const int = Number.parseInt(val);
        if(Number.isNaN(int)) return false;
        if(arg.oneOf && !arg.oneOf.includes(int)) {
                return i18next.t('argument_type.integer.available_options', {
                        lng,
                        options: arg.oneOf.map(opt => `\`${opt}\``)
                                .join(', ')
                });
fork icon260
star icon0
watch icon1

+ 5 other calls in file

161
162
163
164
165
166
167
168
169
170
},
{
  type: 'separator',
},
{
  label: i18next.t('Toggle Developer Tools'),
  role: 'toggleDevTools',
  visible: false,
},
{
fork icon66
star icon94
watch icon6

+ 62 other calls in file

27
28
29
30
31
32
33
34
  .serveMissingKeyRoute(app)
  .serveChangeKeyRoute(app)
  .serveRemoveKeyRoute(app)

//Helper
app.locals.t = i18n.t

}
fork icon10
star icon0
watch icon3

112
113
114
115
116
117
118
119
120
121
        parametersArray.forEach(function(parameter, index) {
            parametersObject[index + 1] = parameter;
        });
    }

    return i18next.t(messageID, parametersObject);
};

i18n.getLanguagesAvailables = function() {
    return languagesAvailables;
fork icon6
star icon46
watch icon6

68
69
70
71
72
73
74
75
76
77
}
private getServiceQuickPickItems(withAnonym: boolean = false): Array<ServiceQuickPick>
{
    let services = [
        {
            label: i18next.t("pastebin.service"),
            description: "",
            service: new pastebin.pastebin(false)
        }, {
            label: i18next.t("github.service"),
fork icon13
star icon33
watch icon8

+ 9 other calls in file

23
24
25
26
27
28
29
30
31
32
i18n.use(backend)
  .init(initOptions);

function t(key, vars) {
  if (isNaN(key) && i18n.exists(key)) {
    return vars ? i18n.t(key, vars) : i18n.t(key);
  }

  return key;
}
fork icon3
star icon22
watch icon3

3
4
5
6
7
8
9
10
11
12

class DeleteCommand extends Command {
    constructor() {
        super('delete', {
            aliases: ['delete', 'del', 'delet'],
            description: i18n.t('commands.delete.description', { returnObjects: true }),
            category: 'wiki',
            channel: 'guild',
            args: [
                {
fork icon5
star icon3
watch icon2

+ 3 other calls in file

28
29
30
31
32
33
34
35
36
37

translation.addTranslations(translations, 'de', 'DE')
var suite = new Benchmark.Suite()
suite
  .add('i18next', () => {
    return i18next.t('test.title', {
      lng: 'de',
      count: 1
    })
  })
fork icon0
star icon2
watch icon2

22
23
24
25
26
27
28
29
30
31
    message += i18next.t('statusMessages.paused') + ' - ' +
      i18next.t('statusMessages.resuming') + ' ' +
      Utils.formatTimeIn(this.timeLeft, this.settings.get('language'))
    return message
  } else {
    message += i18next.t('statusMessages.paused') + ' ' +
      i18next.t('statusMessages.indefinitely')
    return message
  }
}
fork icon404
star icon0
watch icon34

+ 27 other calls in file

82
83
84
85
86
87
88
89
90
91
        }
    });
}

public translate(key: string): string {
    return i18next.t(key);
}

public supportLanguage(language: string): boolean {
    return typeof this.availablesLanguages[language] !== 'undefined';
fork icon383
star icon0
watch icon2

34
35
36
37
38
39
40
41
42
43
var createParameterFromType = function (type, options) {
  var Constructor = mapping[type];
  if (!defined(Constructor)) {
    throw new TerriaError({
      title: i18next.t("models.createParameter.unsupportedErrorTitle"),
      message: i18next.t("models.createParameter.unsupportedErrorMessage", {
        type: type
      })
    });
  }
fork icon331
star icon986
watch icon0

15
16
17
18
19
20
21
22
23
24
var createCatalogMemberFromType = function (type, terria) {
  var Constructor = mapping[type];
  if (!defined(Constructor)) {
    throw new TerriaError({
      title: i18next.t("models.catalog.unsupportedTypeTitle"),
      message: i18next.t("models.catalog.unsupportedTypeMessage", {
        type
      })
    });
  }
fork icon331
star icon986
watch icon0

15
16
17
18
19
20
21
22
23
24
  debug: false, // turn on for debugging
  nsSeparator: '.',
  keySeparator: ':',
})

const t = (key, options) => i18n.t(key, options)

const getFixedT = lang => {
  const t = i18n.getFixedT(lang)
  return t
fork icon3
star icon10
watch icon7

79
80
81
82
83
84
85
86
87
88
toPhoneNumbers: client.responderPhoneNumbers,
fromPhoneNumber: location.phoneNumber,
responderPushId: client.responderPushId,
deviceName: location.displayName,
alertType: newSession.alertType,
message: t('alertStart', { lng: client.language, alertTypeDisplayName, deviceDisplayName: location.displayName }),
reminderTimeoutMillis: client.reminderTimeout * 1000,
fallbackTimeoutMillis: client.fallbackTimeout * 1000,
reminderMessage: t('alertReminder', { lng: client.language, deviceDisplayName: location.displayName }),
fallbackMessage: t('alertFallback', { lng: client.language, deviceDisplayName: location.displayName }),
fork icon2
star icon1
watch icon6

+ 199 other calls in file

29
30
31
32
33
34
35
36
37
38
var url = defaultValue(
  options.url,
  this.terria.configParameters.gnafSearchUrl
);

this.name = i18next.t("viewModels.searchAddresses");
this.gnafApi = defaultValue(
  options.gnafApi,
  new GnafApi(this.terria.corsProxy, url)
);
fork icon1
star icon0
watch icon0

+ 2 other calls in file

47
48
49
50
51
52
53
54
55
56
var suburbs = tableStructure.getColumnWithName(
  i18next.t("map.gnafAddressGeocoder.suburb")
);
smooshColumn(addressesCol, suburbs);
var state = tableStructure.getColumnWithName(
  i18next.t("map.gnafAddressGeocoder.state")
);
smooshColumn(addressesCol, state);
var postCodeCol = tableStructure.getColumnWithName(
  i18next.t("map.gnafAddressGeocoder.postcode")
fork icon1
star icon0
watch icon0

+ 6 other calls in file

97
98
99
100
101
102
103
104
105
106
    resources: require('./i18n'),
    returnObjects: true
});
localizationClient.localize = function localize() {
    const args = arguments;
    const value = i18n.t(...args);
    if (Array.isArray(value))
        return value[Math.floor(Math.random() * value.length)];
    return value;
};
fork icon0
star icon1
watch icon0

127
128
129
130
131
132
133
134
135
136
if (!askBeforeClose) return;

const choice = electron.dialog.showMessageBoxSync(mainWindow, {
  type: 'question',
  buttons: ['Yes', 'No'],
  title: i18n.t('Confirm quit'),
  message: i18n.t('Are you sure you want to quit?'),
});
if (choice === 1) {
  e.preventDefault();
fork icon909
star icon0
watch icon195

216
217
218
219
220
221
222
223
224
225
	{
		name: '\u200b', 
		value: '\u200b'
	},
	{
		name: i18next.t('monthprotector'), 
		value: json.protector.description_fr
	}
)
                    }
fork icon1
star icon1
watch icon1

+ 735 other calls in file

72
73
74
75
76
77
78
79
80
81

const newStaffId = newStaff[0];

// In the first element of response is ID of new staff
if (newStaffId === 0 || newStaffId === undefined) {
  logger.log('error', i18next.t('server.invalid_staff_id'));
}

const responseFields = {
  id: newStaffId,
fork icon1
star icon1
watch icon2

+ 2 other calls in file