Skip to content

Instantly share code, notes, and snippets.

View jacob-jonkman's full-sized avatar

Jacob jacob-jonkman

View GitHub Profile
<trans-unit id="2aj123dsa81327d9812312dsa234fs234" datatype="html">
<source>This is a translatable string!</source>
<context-group purpose="location">
<context context-type="sourcefile">app.component.ts</context>
<context context-type="linenumber">1</context>
</context-group>
</trans-unit>
<div class="container">
<h1 i18n>Translations</h1>
<table>
<tr i18n>
<td>Original</td>
<td>Translated</td>
</tr>
<tr *ngFor="let color of colors">
<td>{{color}}</td> <!-- Will not be translated -->
<td>{{color | translate: language: 'colors' | async}}</td> <!-- Will be translated -->
import { first, map } from 'rxjs/operators';
import { Injectable } from '@angular/core';
import { AngularFireDatabase } from '@angular/fire/database';
@Injectable()
export class TranslateService {
constructor(private angularFireDatabase: AngularFireDatabase) {}
/* Function which does the actual translation. We assume that the terms will always be translated from English to another language */
translateFromEng(term: string, country_code: string, table: string): Promise<string> {
import { Pipe, PipeTransform } from '@angular/core';
import { TranslateService } from './translate.service';
@Pipe({
name: 'translate'
})
export class TranslatePipe implements PipeTransform {
constructor(private translateService: TranslateService) {}
/* Pipe which translates term to the specified language
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';
<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 * 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;');
});
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 { 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,
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']