Skip to content

Commit 0c173f5

Browse files
author
Anton Savoskin
committed
fix(sync): fetch translations in serial order for locize
1 parent afd197f commit 0c173f5

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/providers/locize.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Provider } from './provider';
2-
import { request, showError, showInfo } from '../utils';
2+
import { asyncForEach, request, showError, showInfo } from '../utils';
33
import { Message } from '../types';
44

55
type LocizeKeys = { [key: string]: { value: string; context: { text: string } } };
@@ -18,7 +18,7 @@ export class Locize implements Provider {
1818

1919
async getKeys(locales: string[]) {
2020
const headers = { 'content-type': 'application/json' };
21-
locales.forEach(async locale => {
21+
asyncForEach(locales, async (locale: string) => {
2222
try {
2323
this.locizeKeys[locale] = await request<LocizeKeys>({
2424
headers,

src/utils.ts

+5
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,8 @@ export const request = <T>({ url, body, qs, headers = {}, ...rest }: Options) =>
6060
const format = (time: Date) => time.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1');
6161
export const showError = (message: string) => console.error('\x1b[31m', message, '\x1b[0m');
6262
export const showInfo = (message: string) => console.info(`\x1b[34m[${format(new Date())}]\x1b[0m`, `${message}`);
63+
export const asyncForEach = async (array: any[], callback: any) => {
64+
for (let index = 0; index < array.length; index += 1) {
65+
await callback(array[index], index, array);
66+
}
67+
};

0 commit comments

Comments
 (0)