Skip to content

Commit

Permalink
fix(sync): fetch translations in serial order for locize
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Savoskin committed Jun 14, 2019
1 parent afd197f commit 0c173f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/providers/locize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Provider } from './provider';
import { request, showError, showInfo } from '../utils';
import { asyncForEach, request, showError, showInfo } from '../utils';
import { Message } from '../types';

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

async getKeys(locales: string[]) {
const headers = { 'content-type': 'application/json' };
locales.forEach(async locale => {
asyncForEach(locales, async (locale: string) => {
try {
this.locizeKeys[locale] = await request<LocizeKeys>({
headers,
Expand Down
5 changes: 5 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ export const request = <T>({ url, body, qs, headers = {}, ...rest }: Options) =>
const format = (time: Date) => time.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1');
export const showError = (message: string) => console.error('\x1b[31m', message, '\x1b[0m');
export const showInfo = (message: string) => console.info(`\x1b[34m[${format(new Date())}]\x1b[0m`, `${message}`);
export const asyncForEach = async (array: any[], callback: any) => {
for (let index = 0; index < array.length; index += 1) {
await callback(array[index], index, array);
}
};

0 comments on commit 0c173f5

Please sign in to comment.