Translation infrastructure

This commit is contained in:
Eugene Pankov
2022-01-08 16:02:56 +01:00
parent 04010b58bb
commit 0814d44207
134 changed files with 8137 additions and 889 deletions

View File

@@ -1,11 +1,11 @@
ul.nav-tabs(ngbNav, #nav='ngbNav')
li(ngbNavItem)
a(ngbNavLink) General
a(ngbNavLink, translate) General
ng-template(ngbNavContent)
.row
.col-6(ng:if='hostApp.platform !== Platform.Web')
.form-group
label Device
label(translate) Device
input.form-control(
type='text',
alwaysVisibleTypeahead,
@@ -16,7 +16,7 @@ ul.nav-tabs(ngbNav, #nav='ngbNav')
.col-6
.form-group
label Baud Rate
label(translate) Baud rate
input.form-control(
type='number',
alwaysVisibleTypeahead,
@@ -28,11 +28,11 @@ ul.nav-tabs(ngbNav, #nav='ngbNav')
stream-processing-settings([options]='profile.options')
li(ngbNavItem)
a(ngbNavLink) Advanced
a(ngbNavLink, translate) Advanced
ng-template(ngbNavContent)
.form-line
.header
.title Data bits
.title(translate) Data bits
input.form-control(
type='number',
placeholder='8',
@@ -41,7 +41,7 @@ ul.nav-tabs(ngbNav, #nav='ngbNav')
.form-line
.header
.title Stop bits
.title(translate) Stop bits
input.form-control(
type='number',
placeholder='1',
@@ -50,12 +50,12 @@ ul.nav-tabs(ngbNav, #nav='ngbNav')
.form-line
.header
.title Parity
.title(translate) Parity
select.form-control(
type='text',
[(ngModel)]='profile.options.parity'
)
option(value='none') None
option(value='none', translate) None
option(value='even') Even
option(value='odd') Odd
option(value='mark', ng:if='hostApp.platform === Platform.Windows') Mark
@@ -83,12 +83,12 @@ ul.nav-tabs(ngbNav, #nav='ngbNav')
.form-line
.header
.title Slow feed
.description Sends data one byte at a time
.title(translate) Slow feed
.description(translate) Sends data one byte at a time
toggle([(ngModel)]='profile.options.slowFeed')
li(ngbNavItem)
a(ngbNavLink) Login scripts
a(ngbNavLink, translate) Login scripts
ng-template(ngbNavContent)
login-scripts-settings([options]='profile.options')

View File

@@ -9,8 +9,8 @@
.mr-auto
button.btn.btn-sm.btn-link.mr-3((click)='changeBaudRate()', *ngIf='session && session.open && hostApp.platform !== Platform.Web')
span Change baud rate
span(translate) Change baud rate
button.btn.btn-sm.btn-link((click)='reconnect()', *ngIf='!session || !session.open')
i.fas.fa-redo
span Reconnect
span(translate) Reconnect

View File

@@ -2,7 +2,7 @@
import colors from 'ansi-colors'
import { Component, Injector } from '@angular/core'
import { first } from 'rxjs'
import { Platform, SelectorService } from 'tabby-core'
import { Platform, SelectorService, TranslateService } from 'tabby-core'
import { BaseTerminalTabComponent } from 'tabby-terminal'
import { SerialSession, BAUD_RATES, SerialProfile } from '../api'
@@ -23,6 +23,7 @@ export class SerialTabComponent extends BaseTerminalTabComponent {
constructor (
injector: Injector,
private selector: SelectorService,
private translate: TranslateService,
) {
super(injector)
this.enableToolbar = true
@@ -67,14 +68,13 @@ export class SerialTabComponent extends BaseTerminalTabComponent {
const session = new SerialSession(this.injector, this.profile)
this.setSession(session)
this.write(`Connecting to `)
this.startSpinner('Connecting')
this.startSpinner(this.translate.instant('Connecting'))
try {
await this.session!.start()
this.stopSpinner()
session.emitServiceMessage('Port opened')
session.emitServiceMessage(this.translate.instant('Port opened'))
} catch (e) {
this.stopSpinner()
this.write(colors.black.bgRed(' X ') + ' ' + colors.red(e.message) + '\r\n')
@@ -89,7 +89,7 @@ export class SerialTabComponent extends BaseTerminalTabComponent {
this.session?.resize(this.size.columns, this.size.rows)
})
this.attachSessionHandler(this.session!.destroyed$, () => {
this.write('Press any key to reconnect\r\n')
this.write(this.translate.instant('Press any key to reconnect') + '\r\n')
this.input$.pipe(first()).subscribe(() => {
if (!this.session?.open) {
this.reconnect()
@@ -114,9 +114,12 @@ export class SerialTabComponent extends BaseTerminalTabComponent {
}
async changeBaudRate () {
const rate = await this.selector.show('Baud rate', BAUD_RATES.map(x => ({
name: x.toString(), result: x,
})))
const rate = await this.selector.show(
this.translate.instant('Baud rate'),
BAUD_RATES.map(x => ({
name: x.toString(), result: x,
})),
)
this.serialPort.update({ baudRate: rate })
this.profile!.options.baudrate = rate
}

View File

@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core'
import { HotkeyDescription, HotkeyProvider } from 'tabby-core'
import { HotkeyDescription, HotkeyProvider, TranslateService } from 'tabby-core'
/** @hidden */
@Injectable()
@@ -7,14 +7,16 @@ export class SerialHotkeyProvider extends HotkeyProvider {
hotkeys: HotkeyDescription[] = [
{
id: 'serial',
name: 'Show Serial connections',
name: this.translate.instant('Show Serial connections'),
},
{
id: 'restart-serial-session',
name: 'Restart current serial session',
name: this.translate.instant('Restart current serial session'),
},
]
constructor (private translate: TranslateService) { super() }
async provide (): Promise<HotkeyDescription[]> {
return this.hotkeys
}

View File

@@ -3,7 +3,7 @@ import SerialPort from 'serialport'
import WSABinding from 'serialport-binding-webserialapi'
import deepClone from 'clone-deep'
import { Injectable } from '@angular/core'
import { ProfileProvider, NewTabParameters, SelectorService, HostAppService, Platform } from 'tabby-core'
import { ProfileProvider, NewTabParameters, SelectorService, HostAppService, Platform, TranslateService } from 'tabby-core'
import { SerialProfileSettingsComponent } from './components/serialProfileSettings.component'
import { SerialTabComponent } from './components/serialTab.component'
import { SerialService } from './services/serial.service'
@@ -12,7 +12,7 @@ import { BAUD_RATES, SerialProfile } from './api'
@Injectable({ providedIn: 'root' })
export class SerialProfilesService extends ProfileProvider<SerialProfile> {
id = 'serial'
name = 'Serial'
name = this.translate.instant('Serial')
settingsComponent = SerialProfileSettingsComponent
configDefaults = {
options: {
@@ -38,6 +38,7 @@ export class SerialProfilesService extends ProfileProvider<SerialProfile> {
private selector: SelectorService,
private serial: SerialService,
private hostApp: HostAppService,
private translate: TranslateService,
) {
super()
if (hostApp.platform === Platform.Web) {
@@ -51,7 +52,7 @@ export class SerialProfilesService extends ProfileProvider<SerialProfile> {
{
id: `serial:web`,
type: 'serial',
name: 'Serial connection',
name: this.translate.instant('Serial connection'),
icon: 'fas fa-microchip',
isBuiltin: true,
} as SerialProfile,
@@ -62,7 +63,7 @@ export class SerialProfilesService extends ProfileProvider<SerialProfile> {
{
id: `serial:template`,
type: 'serial',
name: 'Serial connection',
name: this.translate.instant('Serial connection'),
icon: 'fas fa-microchip',
isBuiltin: true,
isTemplate: true,
@@ -70,7 +71,9 @@ export class SerialProfilesService extends ProfileProvider<SerialProfile> {
...(await this.serial.listPorts()).map(p => ({
id: `serial:port-${slugify(p.name).replace('.', '-')}`,
type: 'serial',
name: p.description ? `Serial: ${p.description}` : 'Serial',
name: p.description ?
this.translate.instant('Serial: {description}', p) :
this.translate.instant('Serial'),
icon: 'fas fa-microchip',
isBuiltin: true,
options: {
@@ -83,9 +86,12 @@ export class SerialProfilesService extends ProfileProvider<SerialProfile> {
async getNewTabParameters (profile: SerialProfile): Promise<NewTabParameters<SerialTabComponent>> {
if (!profile.options.baudrate) {
profile = deepClone(profile)
profile.options.baudrate = await this.selector.show('Baud rate', BAUD_RATES.map(x => ({
name: x.toString(), result: x,
})))
profile.options.baudrate = await this.selector.show(
this.translate.instant('Baud rate'),
BAUD_RATES.map(x => ({
name: x.toString(), result: x,
})),
)
}
return {
type: SerialTabComponent,