Skip to content

Commit

Permalink
fix(sync): upload new messages for all locales
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Savoskin committed Jun 17, 2019
1 parent d631bf2 commit 781aaae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/commands/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}
}
6 changes: 4 additions & 2 deletions src/providers/locize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand All @@ -56,7 +56,9 @@ export class Locize implements Provider {
const response = await request<string>({
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)}`);
Expand Down
2 changes: 1 addition & 1 deletion src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { Message } from '../types';
export interface Provider {
getKeys(locales: string[]): Promise<void>;
getMessage(locale: string, id: string): string;
uploadMessages(messages: Message[], locales: string[]): Promise<void>;
uploadMessages(messages: Message[], locale: string): Promise<void>;
getNewMessages(): string[];
}

0 comments on commit 781aaae

Please sign in to comment.