diff --git a/src/commands/sync.ts b/src/commands/sync.ts index 0a1e9aa..92051b1 100644 --- a/src/commands/sync.ts +++ b/src/commands/sync.ts @@ -106,10 +106,13 @@ export default class Extract extends Base { const newMessages = this.provider.getNewMessages(); if (newMessages.length > 0) { showInfo(`New translation keys: ${newMessages.length}`); - await this.provider.uploadMessages(newMessages.map(id => this.messages[locales[0]][id]), locales); - asyncForEach(locales, locale => - this.provider!.uploadMessages(newMessages.map(id => this.messages[locale][id]), locales), - ); + if (provider === 'locize') { + asyncForEach(locales, locale => + this.provider!.uploadMessages(newMessages.map(id => this.messages[locale][id]), locale), + ); + } else { + await this.provider.uploadMessages(newMessages.map(id => this.messages[locales[0]][id]), 'en'); + } } } } diff --git a/src/providers/locize.ts b/src/providers/locize.ts index 0824241..876970a 100644 --- a/src/providers/locize.ts +++ b/src/providers/locize.ts @@ -43,7 +43,7 @@ export class Locize implements Provider { return ''; } - async uploadMessages(messages: Message[], locales: string[]) { + async uploadMessages(messages: Message[], locale: string) { const headers = { Authorization: `Bearer ${this.apiKey}`, 'content-type': 'application/json' }; const body = messages.reduce( (acc, { id, message, defaultMessage, description }) => { @@ -56,7 +56,9 @@ export class Locize implements Provider { const response = await request({ headers, body, - url: `${BASE_URL}/missing/${this.projectId}/${this.version}/en/${this.namespace}`, + url: `${BASE_URL}/${locale === 'en' ? 'missing' : 'update'}/${this.projectId}/${this.version}/${locale}/${ + this.namespace + }`, method: 'POST', }); showInfo(`Response from locize: ${JSON.stringify(response, null, 2)}`); diff --git a/src/providers/provider.ts b/src/providers/provider.ts index 899040d..6e908b6 100644 --- a/src/providers/provider.ts +++ b/src/providers/provider.ts @@ -3,6 +3,6 @@ import { Message } from '../types'; export interface Provider { getKeys(locales: string[]): Promise; getMessage(locale: string, id: string): string; - uploadMessages(messages: Message[], locales: string[]): Promise; + uploadMessages(messages: Message[], locale: string): Promise; getNewMessages(): string[]; }