Skip to content

Commit

Permalink
feat: add internationalization
Browse files Browse the repository at this point in the history
  • Loading branch information
4gray committed Feb 20, 2021
1 parent 74b29c9 commit 0f8ca2a
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export class AppComponent {
Object.keys(settings).length > 0 &&
settings.epgUrl
) {
this.translate.setDefaultLang(settings.language ?? 'en');
this.electronService.ipcRenderer.send(EPG_FETCH, {
url: settings.epgUrl,
});
Expand Down
6 changes: 6 additions & 0 deletions src/app/settings/language.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Enum with all languages that are available in the application
*/
export enum Language {
ENGLISH = 'en',
}
28 changes: 28 additions & 0 deletions src/app/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@
</p>
</div>
</mat-list-item>
<mat-list-item>
<div matLine fxLayout="row">
<p fxFlex>
{{ 'SETTINGS.LANGUAGE' | translate }}
</p>
<p fxFlex fxLayoutAlign="start center">
<mat-form-field appearance="fill">
<mat-label>{{
'SETTINGS.VIDEO_PLAYER_PLACEHOLDER'
| translate
}}</mat-label>
<mat-select formControlName="language">
<mat-option
*ngFor="
let language of languageEnum
| keyvalue
"
[value]="language.value"
>{{
'LANGUAGES.' + language.key
| translate
}}</mat-option
>
</mat-select>
</mat-form-field>
</p>
</div>
</mat-list-item>
<mat-list-item>
<div matLine fxLayout="row">
<p fxFlex>{{ 'SETTINGS.VERSION' | translate }}</p>
Expand Down
10 changes: 8 additions & 2 deletions src/app/settings/settings.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ button {
text-transform: uppercase;
}

::ng-deep .mat-card {
border-radius: 0 !important;
::ng-deep{
.mat-card {
border-radius: 0 !important;
}

.mat-list-item {
height: 70px !important;
}
}
21 changes: 16 additions & 5 deletions src/app/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import * as semver from 'semver';
import { ElectronService } from '../services/electron.service';
import { ChannelQuery } from '../state';
import { EPG_FETCH } from '../../../ipc-commands';
import { Language } from './language.enum';

/** Url of the package.json file in the app repository, required to get the version of the released app */
const PACKAGE_JSON_URL =
'https://raw.githubusercontent.com/4gray/iptvnator/master/package.json';

@Component({
selector: 'app-settings',
Expand All @@ -21,9 +26,8 @@ export class SettingsComponent implements OnInit, OnDestroy {
/** Subscription object */
private subscription: Subscription = new Subscription();

/** Url of the package.json file in the app repository, required to get the version of the released app */
latestPackageJsonUrl =
'https://raw.githubusercontent.com/4gray/iptvnator/master/package.json';
/** List with available languages as enum */
languageEnum = Language;

/** Player options */
players = [
Expand Down Expand Up @@ -72,13 +76,14 @@ export class SettingsComponent implements OnInit, OnDestroy {
private translate: TranslateService
) {
this.settingsForm = this.formBuilder.group({
player: ['videojs'], // default value
player: ['videojs'],
epgUrl: '',
language: Language.ENGLISH,
});

this.subscription.add(
this.http
.get(this.latestPackageJsonUrl)
.get(PACKAGE_JSON_URL)
.subscribe((response: { version: string }) => {
this.version = this.electronService.getAppVersion();
const isOutdated = semver.lt(
Expand Down Expand Up @@ -111,6 +116,9 @@ export class SettingsComponent implements OnInit, OnDestroy {
this.settingsForm.setValue({
player: settings.player ? settings.player : 'videojs',
epgUrl: settings.epgUrl ? settings.epgUrl : '',
language: settings.language
? settings.language
: Language.ENGLISH,
});
}
})
Expand All @@ -137,6 +145,9 @@ export class SettingsComponent implements OnInit, OnDestroy {
if (this.settingsForm.value.epgUrl) {
this.fetchEpg();
}
this.translate.setDefaultLang(
this.settingsForm.value.language
);
})
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/settings/settings.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Language } from './language.enum';

export type VideoPlayerType = 'html5' | 'videojs';

/**
Expand All @@ -6,4 +8,5 @@ export type VideoPlayerType = 'html5' | 'videojs';
export interface Settings {
player: VideoPlayerType;
epgUrl: string;
language: Language;
}
8 changes: 7 additions & 1 deletion src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"SAVE_CHANGES": "Save changes",
"BACK_TO_HOME": "Back to home",
"NEW_VERSION_AVAILABLE": "There is a new version available",
"LATEST_VERSION": "You are using the latest version"
"LATEST_VERSION": "You are using the latest version",
"LANGUAGE": "Language"
},
"CHANNELS": {
"SEARCH_CHANNEL": "Search channel",
Expand Down Expand Up @@ -76,5 +77,10 @@
"EPG_NOT_AVAILABLE_DATE": "Ooops, EPG is not available for the selected date",
"EPG_NOT_AVAILABLE_CHANNEL_TITLE": "Ooops, EPG is not available for this channel.",
"EPG_NOT_AVAILABLE_CHANNEL_DESCRIPTION": "Please add/change the url of EPG list the settings of the app."
},
"LANGUAGES": {
"ENGLISH": "English",
"RUSSIAN": "Russian",
"GERMAN": "German"
}
}

0 comments on commit 0f8ca2a

Please sign in to comment.