Skip to content

Instantly share code, notes, and snippets.

View jacob-jonkman's full-sized avatar

Jacob jacob-jonkman

View GitHub Profile
function constructTranslationsForLanguage(lang, translations): Promise<any> {
return request(listTermsOptions)
.then(body => JSON.parse(body).result.terms)
.then(terms => {
for (const index in terms) {
if (terms.hasOwnProperty(index)) {
const term = encodeAsFirebaseKey(terms[index]['term']);
if (!translations[term]) {
translations[term] = {};
}
function constructTranslationsperLanguage(project_id: string): Promise<any> {
const translations = {};
return request(listLanguagesOptions)
.then(response => JSON.parse(response).result.languages.map(lang => lang['code']))
.then(languages => {
return Promise.all(languages.map(lang => {
listTermsOptions.formData.language = lang;
listTermsOptions.formData.id = project_id;
return constructTranslationsForLanguage(lang, translations)
}))
import * as request from 'request-promise';
import * as firebase from 'firebase';
import * as admin from 'firebase-admin';
import { projectId } from './poeditor-params';
import { Project } from './project';
import { listProjectOptions, listLanguagesOptions, listTermsOptions } from './api-options';
import { blacklisted_projects } from './blacklisted_projects';
const serviceAccount = require('./serviceAccountKey.json');
firebase.initializeApp({
function writeTranslationsPerProject(projects: Project[]): void {
Promise.all(projects.map(project => {
listLanguagesOptions.formData.id = project.id;
return constructTranslationsperLanguage(project.id)
.then(translations => {
return firebase.database().ref('translations/' + project.name.replace('Winestep-', '') + '/').set(translations)
.then(() => console.log(project.name, 'done!'));
})
})).then(() => process.exit());
}
function selectValidProjects(): Promise<Project[]> {
return request(listProjectOptions)
.then(response => JSON.parse(response).result.projects)
.then(projects => {
const projectsList: Project[] = [];
projects.forEach(project => {
if (!is_project_blacklisted(project)) {
projectsList.push({
name: project['name'],
id: project['id']
import { api_key } from './poeditor-params';
const listLanguageURI = 'https://api.poeditor.com/v2/languages/list';
const listTermsURI = 'https://api.poeditor.com/v2/terms/list';
const listProjectsURI = 'https://api.poeditor.com/v2/projects/list';
// Options for reading the projects in POEditor
export const listProjectOptions = {
method: 'POST',
uri: listProjectsURI,
import * as fs from 'fs';
const languages = ['eng', 'fra', 'nl'];
const regex = /(\&lt;x(\s+([^\/]*))\/\&gt;)/gi;
languages.forEach(lang => {
const data: string = fs.readFileSync(`../../src/i18n/messages.${lang}.xlf`, 'utf-8');
const dataLines: string[] = data.split('\n');
const rewrittenData = dataLines.map((line: string) => {
import * as fs from 'fs';
const data: string = fs.readFileSync('../../i18n/messages.xlf', 'utf-8');
const dataLines: string[] = data.split('\n');
const regex = /(<x(\s+([^>]*))*\/>)/gi;
const rewrittenData = dataLines.map((line: string) => {
return line.replace(regex, '&lt;x$2/&gt;');
});
<trans-unit id="5e4f32f1b3fa8e5261a2735d2ac4cccdda18a40b" datatype="html">
<source>
<x id="START_TABLE_CELL" ctype="x-td" equiv-text="&lt;td&gt;"/>Original<x id="CLOSE_TABLE_CELL" ctype="x-td" equiv-text="&lt;/td&gt;"/>
<x id="START_TABLE_CELL" ctype="x-td" equiv-text="&lt;td&gt;"/>Translated<x id="CLOSE_TABLE_CELL" ctype="x-td" equiv-text="&lt;/td&gt;"/>
</source>
<context-group purpose="location">
<context context-type="sourcefile">app/app.component.html</context>
<context context-type="linenumber">4</context>
</context-group>
</trans-unit>
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
public colors = ['blue', 'red', 'yellow'];
public language = 'eng';