Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add select language component #7

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/demo/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"main": "apps/demo/src/main.ts",
"polyfills": ["zone.js"],
"tsConfig": "apps/demo/tsconfig.app.json",
"assets": ["apps/demo/src/assets"],
"assets": ["apps/demo/src/assets","@sio/core/assets/"],
"styles": [
"apps/demo/src/theme/variables.scss",
"apps/demo/src/global.scss"
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/src/app/home/home.page.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<sio-page title="test" color="primary">
{{ 'M_HOME' | translate }}
<sio-language-selector></sio-language-selector>
</sio-page>
42 changes: 21 additions & 21 deletions apps/demo/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,41 @@ import { SioCoreEnvironmentInterface, SioCorePluginServiceConfigModel } from '@s

export const environment: SioCoreEnvironmentInterface = {
production: false,
language: {
avaibles: ['it', 'en'],
default: 'it',
fallback: 'en',
},
logLevel: 0,
plugins: [
NgxsLoggerPluginModule.forRoot(),
NgxsReduxDevtoolsPluginModule.forRoot(),
],
backend: {},
app: {
'language': {
'avaibles': ['it', 'en'],
'default': 'it',
'fallback': 'en',
},
'sidemenu': 'toogle',
title: 'Demo App',
urls: {
'title': 'Demo App',
'urls': {
login: '',
redirectTo: '',
},
menu: {
main: {
id: 'main',
items: {
1: { id: 1, icon: 'home', url: 'home', badge: 3 },
2: { id: 2, icon: 'information-circle', url: 'about' },
3: { id: 3, icon: 'settings', url: 'settings' }
'menu': {
'main': {
'id': 'main',
'items': {
1: { 'id': 1, 'icon': 'home', 'url': 'home', badge: 3 },
2: { 'id': 2, 'icon': 'information-circle', 'url': 'about' },
3: { 'id': 3, 'icon': 'settings', 'url': 'settings' }
},
},
logged: {
id: 'logged',
items: {
'logged': {
'id': 'logged',
'items': {
1: {
id: 1,
icon: 'person',
caption: 'T_MENU_LOGGED_PROFILE',
url: '/auth/profile',
'id': 1,
'icon': 'person',
'caption': 'T_MENU_LOGGED_PROFILE',
'url': '/auth/profile',
},
},
},
Expand Down
6 changes: 3 additions & 3 deletions libs/core/src/lib/components/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ export class SioCoreAppComponent implements OnInit, OnDestroy {

ngOnInit(): void {
(async () => {
this.translateService.addLangs(['en','it']);
this.translateService.use('en');
this.sioCoreLoggerService.info('check platform...');
this.sioCoreLoggerService.info('await for platform avaible...');
let platform = await this.platform.ready();
this.translateService.addLangs(this.sioCoreEnvironmentService.config.app.language.avaibles);
this.sioCoreLoggerService.info('Check platform...');
switch (platform) {
case 'dom':
platform = 'browser';
Expand Down
5 changes: 5 additions & 0 deletions libs/core/src/lib/components/app/app.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { SioCoreMenuInterface } from '../menu';
export interface SioCoreAppCompomentInterface {
title: string;
//style: number;
language : {
default: string,
fallback: string,
avaibles: string[],
};
sidemenu: SioSideMenuType;
fullmode?: boolean;
menu?: { [id: string]: SioCoreMenuInterface };
Expand Down
5 changes: 5 additions & 0 deletions libs/core/src/lib/components/app/store/app.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { SioCoreTabsStateModel } from '../../tabs';

export interface SioCoreAppComponentStateModel extends SioCoreAppCompomentInterface {
title: string;
language: {
default: string,
fallback: string,
avaibles: string[],
},
dark: boolean | undefined;
split: boolean | undefined;
urls: {
Expand Down
10 changes: 10 additions & 0 deletions libs/core/src/lib/components/app/store/app.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ const APP_STATE_TOKEN = new StateToken<SioCoreAppComponentStateModel>('app');
@State<SioCoreAppComponentStateModel>({
name: APP_STATE_TOKEN,
defaults: {
'language': {
'avaibles': ['en'],
'default' : 'en',
'fallback' : 'en'
},
'title': 'APP_TITLE',
'dark': false,
'sidemenu': 'none',
Expand Down Expand Up @@ -55,6 +60,11 @@ export class SioCoreAppComponentState extends NgxsDataRepository<SioCoreAppCompo
return this.snapshot.split;
}

@Computed()
get currentLanguage() {
return this.snapshot.language.default;
}

@Selector()
static error(state: SioCoreAppComponentStateModel) {
return state.errors;
Expand Down
3 changes: 3 additions & 0 deletions libs/core/src/lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import { SioCoreListComponent } from './list';
import { SioCoreItemComponent } from './item';
import { SioCoreModalComponent } from './modal';
import { SioCoreSlideComponent } from './slide';
import { SioCoreLanguageSelectorComponent } from './language-selector/language-selector.component';

export { SioCoreAppComponent } from './app';
export { SioCoreLanguageSelectorComponent } from './language-selector/language-selector.component';
export { SioCoreCardComponent } from './card';
export { SioCoreDarkModeToggleComponent } from './dark-mode-toogle';
export { SioCoreFormComponent } from './form';
Expand All @@ -34,6 +36,7 @@ export { SioCoreSlideComponent } from './slide';

export const SioCoreComponents = [
SioCoreAppComponent,
SioCoreLanguageSelectorComponent,
SioCoreCardComponent,
SioCoreDarkModeToggleComponent,
SioCoreFormComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<ion-item>
<ion-select [label]="this.label" (ionChange)="this.onChange($event)">
<ion-select-option value="it">Italiano</ion-select-option>
<ion-select-option value="en">Inglese</ion-select-option>
</ion-select>
</ion-item>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:host {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { IonToggle } from '@ionic/angular';
import { Select } from '@ngxs/store';
import { Observable } from 'rxjs';
import { Loggable, SioCoreLoggerService } from '../../services';
import { SioColorType } from '../../shared/shared.type';
import { SioCoreAppComponentState } from '../../store';
import { TranslateService } from '@ngx-translate/core';

@Loggable()
@Component({
selector: 'sio-language-selector',
templateUrl: './language-selector.component.html',
styleUrls: ['./language-selector.component.scss'],
})
export class SioCoreLanguageSelectorComponent implements OnInit {
@Input() public caption = 'L_LANGUAGE';
@Input() public style: 'default' | undefined = undefined;
@Input() public color: SioColorType;
@Input() public icon = 'sunny';

public label = 'L_LANGUAGE';

//@Select(SioCoreAppComponentState) darkmode$!: Observable<boolean>;

//@ViewChild('darkmode_toggle', { static: true }) ionToggle!: IonToggle;

// eslint-disable-next-line @typescript-eslint/no-empty-function
constructor(
private sioCoreLoggerService: SioCoreLoggerService,
public sioCoreAppComponentState: SioCoreAppComponentState,
private translateService: TranslateService,
) {}

ngOnInit(): void {
null;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public onChange(event: any) {
this.sioCoreLoggerService.debug('set language to ' + event.detail.value);
this.translateService.use(event.detail.value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import { SioCorePluginServiceConfigModel } from "../plugins";
export interface SioCoreEnvironmentInterface {
logLevel: number,
backend : SioCorePluginServiceConfigModel,
language: {
default: string,
fallback: string,
avaibles: string[],
}
production: boolean,
plugins?: ModuleWithProviders<unknown>[],
app: SioCoreAppCompomentInterface,
Expand Down
11 changes: 6 additions & 5 deletions libs/core/src/lib/services/environment/environment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ export class SioCoreEnvironmentConfig implements SioCoreEnvironmentInterface {
production = false;
logLevel = LogLevel.Info;
backend = {};
language = {
default: 'en',
fallback: 'en',
avaibles: ['it', 'en'],
};

app: SioCoreAppCompomentInterface = {
title: 'TEST',
language : {
default: 'en',
fallback: 'en',
avaibles: ['it', 'en'],
},
sidemenu: 'overlay',
//dark: false,
menu: {},
Expand Down
Loading