Skip to content

Commit 5dec269

Browse files
Adding default locale config for momentjs to docs
1 parent 7137706 commit 5dec269

File tree

2 files changed

+115
-131
lines changed

2 files changed

+115
-131
lines changed

README.md

Lines changed: 17 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ In current context, dependencies such as `react-native-document-picker` and (if
294294
295295
## Internationalization
296296
297-
Instance of this class `Streami18n` should be provided to Chat component to handle translations.
297+
Instance of class `Streami18n` should be provided to Chat component to handle translations.
298298
Stream provides following list of in-built translations for components:
299299
300300
1. English (en)
@@ -307,131 +307,27 @@ Stream provides following list of in-built translations for components:
307307
308308
Default language is English. Simplest way to start using chat components in one of the in-built languages would be following:
309309
310-
### Docs
310+
Simplest way to start using chat components in one of the in-built languages would be following:
311311
312-
- **Text translations**
313-
314-
Simplest way to start using chat components in one of the in-built languages would be following:
315-
316-
```js static
317-
const i18n = new Streami18n({ language: 'nl' });
318-
<Chat client={chatClient} i18nInstance={i18n}>
319-
...
320-
</Chat>;
321-
```
322-
323-
If you would like to override certain keys in in-built translation.
324-
UI will be automatically updated in this case.
325-
326-
```js static
327-
const i18n = new Streami18n({
328-
language: 'nl',
329-
translationsForLanguage: {
330-
'Nothing yet...': 'Nog Niet ...',
331-
'{{ firstUser }} and {{ secondUser }} are typing...':
332-
'{{ firstUser }} en {{ secondUser }} zijn aan het typen...',
333-
},
334-
});
335-
```
312+
```js static
313+
const i18n = new Streami18n({ language: 'nl' });
314+
<Chat client={chatClient} i18nInstance={i18n}>
315+
...
316+
</Chat>;
317+
```
336318

337-
If you would like to register additional languages, use registerTranslation. You can add as many languages as you want:
319+
If you would like to override certain keys in in-built translation.
320+
UI will be automatically updated in this case.
338321

339-
```js static
340-
i18n.registerTranslation('zh', {
322+
```js static
323+
const i18n = new Streami18n({
324+
language: 'nl',
325+
translationsForLanguage: {
341326
'Nothing yet...': 'Nog Niet ...',
342327
'{{ firstUser }} and {{ secondUser }} are typing...':
343328
'{{ firstUser }} en {{ secondUser }} zijn aan het typen...',
344-
});
345-
346-
<Chat client={chatClient} i18nInstance={i18n}>
347-
...
348-
</Chat>;
349-
```
350-
351-
You can use the same function to add whole new language as well.
352-
353-
```js static
354-
const i18n = new Streami18n();
355-
356-
i18n.registerTranslation('mr', {
357-
'Nothing yet...': 'काहीही नाही ...',
358-
'{{ firstUser }} and {{ secondUser }} are typing...':
359-
'{{ firstUser }} आणि {{ secondUser }} टीपी करत आहेत ',
360-
});
361-
362-
// Make sure to call setLanguage to reflect new language in UI.
363-
i18n.setLanguage('it');
364-
<Chat client={chatClient} i18nInstance={i18n}>
365-
...
366-
</Chat>;
367-
```
368-
369-
- **Datetime translations**
370-
371-
Stream components uses [momentjs](http://momentjs.com/) internally to format datetime stamp.
372-
e.g., in ChannelPreview, MessageContent components.
373-
374-
When you use any of the built-in translations, datetime will also be translated in corresponding langauge
375-
by default. If you would like to stick with english language for datetimes, you can set `disableDateTimeTranslations` to true.
376-
377-
You can override the locale config for momentjs.
378-
379-
e.g.,
380-
381-
```js static
382-
const i18n = new Streami18n({
383-
language: 'nl',
384-
momentLocaleConfigForLanguage: {
385-
months: [...],
386-
monthsShort: [...],
387-
calendar: {
388-
sameDay: '...'
389-
}
390-
}
391-
});
392-
```
393-
394-
Similarly, you can add locale config for moment while registering translation via `registerTranslation` function.
395-
396-
e.g.,
397-
398-
```js static
399-
const i18n = new Streami18n();
400-
401-
i18n.registerTranslation(
402-
'mr',
403-
{
404-
'Nothing yet...': 'काहीही नाही ...',
405-
'{{ firstUser }} and {{ secondUser }} are typing...': '{{ firstUser }} आणि {{ secondUser }} टीपी करत आहेत ',
406329
},
407-
{
408-
months: [...],
409-
monthsShort: [...],
410-
calendar: {
411-
sameDay: '...'
412-
}
413-
}
414-
);
415-
```
416-
417-
Momentjs provides locale config for plenty of languages, you can check the whole list of locale configs at following url
418-
419-
https://github.com/moment/moment/tree/develop/locale
420-
421-
Stream uses locale configs provided by momentjs for built-in languages. You can also use one of these locale configs whiles registering
422-
a new language. If you would liek to use the locale provided by momentjs as it is, simply import the file in your project.
423-
424-
e.g.,
425-
426-
```js static
427-
428-
// Registering locale config for Danish language
429-
import 'moment/locale/da';
330+
});
331+
```
430332

431-
const i18n = new Streami18n({
432-
language: 'da',
433-
translationsForLanguage: {
434-
...
435-
},
436-
});
437-
```
333+
Please read this docs on i18n for more details and further customizations - https://getstream.github.io/stream-chat-react-native/#streami18n

src/components/docs/Streami18n.md

Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,93 @@ Stream provides following list of in-built translations:
172172
});
173173
```
174174

175+
The default `en` locale config from moment is as follow:
176+
177+
```json
178+
{
179+
"months": [
180+
"January",
181+
"February",
182+
"March",
183+
"April",
184+
"May",
185+
"June",
186+
"July",
187+
"August",
188+
"September",
189+
"October",
190+
"November",
191+
"December"
192+
],
193+
"monthsShort": [
194+
"Jan",
195+
"Feb",
196+
"Mar",
197+
"Apr",
198+
"May",
199+
"Jun",
200+
"Jul",
201+
"Aug",
202+
"Sep",
203+
"Oct",
204+
"Nov",
205+
"Dec"
206+
],
207+
"week": {
208+
"dow": 0,
209+
"doy": 6
210+
},
211+
"weekdays": [
212+
"Sunday",
213+
"Monday",
214+
"Tuesday",
215+
"Wednesday",
216+
"Thursday",
217+
"Friday",
218+
"Saturday"
219+
],
220+
"weekdaysMin": ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
221+
"weekdaysShort": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
222+
"calendar": {
223+
"sameDay": "[Today at] LT",
224+
"nextDay": "[Tomorrow at] LT",
225+
"nextWeek": "dddd [at] LT",
226+
"lastDay": "[Yesterday at] LT",
227+
"lastWeek": "[Last] dddd [at] LT",
228+
"sameElse": "L"
229+
},
230+
"longDateFormat": {
231+
"LTS": "h:mm:ss A",
232+
"LT": "h:mm A",
233+
"L": "MM/DD/YYYY",
234+
"LL": "MMMM D, YYYY",
235+
"LLL": "MMMM D, YYYY h:mm A",
236+
"LLLL": "dddd, MMMM D, YYYY h:mm A"
237+
},
238+
"invalidDate": "Invalid date",
239+
"ordinal": "%d.",
240+
"dayOfMonthOrdinalParse": /\\d{1,2}(th|st|nd|rd)/,
241+
"relativeTime": {
242+
"future": "in %s",
243+
"past": "%s ago",
244+
"s": "a few seconds",
245+
"ss": "%d seconds",
246+
"m": "a minute",
247+
"mm": "%d minutes",
248+
"h": "an hour",
249+
"hh": "%d hours",
250+
"d": "a day",
251+
"dd": "%d days",
252+
"M": "a month",
253+
"MM": "%d months",
254+
"y": "a year",
255+
"yy": "%d years"
256+
},
257+
"meridiemParse": /[ap]\\.?m?\\.?/i,
258+
"abbr": "en"
259+
}
260+
```
261+
175262
Similarly, you can add locale config for moment while registering translation via `registerTranslation` function.
176263

177264
e.g.,
@@ -194,24 +281,25 @@ Stream provides following list of in-built translations:
194281
}
195282
);
196283
```
284+
197285
Momentjs provides locale config for plenty of languages, you can check the whole list of locale configs at following url
198286

199287
https://github.com/moment/moment/tree/develop/locale
200288

201289
Stream uses locale configs provided by momentjs for built-in languages. You can also use one of these locale configs whiles registering
202290
a new language. If you would liek to use the locale provided by momentjs as it is, simply import the file in your project.
203291

204-
e.g.,
292+
e.g.,
205293

206294
```js static
207295

208-
// Registering locale config for Danish language
209-
import 'moment/locale/da';
296+
// Registering locale config for Danish language
297+
import 'moment/locale/da';
210298

211-
const i18n = new Streami18n({
212-
language: 'da',
213-
translationsForLanguage: {
214-
...
215-
},
216-
});
217-
```
299+
const i18n = new Streami18n({
300+
language: 'da',
301+
translationsForLanguage: {
302+
...
303+
},
304+
});
305+
```

0 commit comments

Comments
 (0)