Commit c2c56b81 authored by 神楽坂玲奈's avatar 神楽坂玲奈

i18n

parent 46407b4a
<h1>{{name}}</h1> <h1>{{'app.' + currentApp.id + '.name' | translate}}</h1>
<h2>{{appsService._aa}}</h2> <h2>{{appsService._aa}}</h2>
<div *ngIf="!isInstalled"> <div *ngIf="!isInstalled">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#install-modal">安装</button> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#install-modal">安装</button>
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
<tbody> <tbody>
<tr *ngFor="let mod of mods; let i = index"> <tr *ngFor="let mod of mods; let i = index">
<th scope="row">{{i + 1}}</th> <th scope="row">{{i + 1}}</th>
<td>{{searchApp(mod.id).name[searchApp(mod.id).locales[0]]}}</td> <td>{{'app.' + mod.id + '.name' | translate}}</td>
<td>{{mod.type}}</td> <td>{{mod.type}}</td>
<td *ngIf="checkInstall(mod.id)"> <td *ngIf="checkInstall(mod.id)">
<button type="button" class="btn btn-danger btn-sm">卸载</button></td> <button type="button" class="btn btn-danger btn-sm">卸载</button></td>
......
import {Injectable} from '@angular/core'; import {Injectable, transition} from '@angular/core';
import {Http} from '@angular/http'; import {Http} from '@angular/http';
import 'rxjs/Rx'; import 'rxjs/Rx';
import {App} from "./app"; import {App} from "./app";
import {AppLocal} from "./app-local"; import {AppLocal} from "./app-local";
import {TranslateService} from "ng2-translate";
@Injectable() @Injectable()
export class AppsService { export class AppsService {
constructor(private http: Http) { constructor(private http: Http, private translate: TranslateService) {
let loop = setInterval(()=>{ let loop = setInterval(()=> {
this.aria2.tellActive().then((res)=>{ this.aria2.tellActive().then((res)=> {
console.log('res:', res); console.log('res:', res);
this.downloadsInfo = res; this.downloadsInfo = res;
}) })
...@@ -23,7 +24,7 @@ export class AppsService { ...@@ -23,7 +24,7 @@ export class AppsService {
electron = window['System']._nodeRequire('electron'); electron = window['System']._nodeRequire('electron');
Aria2 = window['System']._nodeRequire('aria2'); Aria2 = window['System']._nodeRequire('aria2');
data : App[]; data: App[];
downloadsInfo = {}; downloadsInfo = {};
...@@ -32,17 +33,17 @@ export class AppsService { ...@@ -32,17 +33,17 @@ export class AppsService {
_aria2; _aria2;
get aria2() { get aria2() {
if(!this._aria2) { if (!this._aria2) {
this._aria2 = new this.Aria2(); this._aria2 = new this.Aria2();
console.log("new aria2"); console.log("new aria2");
this._aria2.onopen = ()=>{ this._aria2.onopen = ()=> {
console.log('aria2 open'); console.log('aria2 open');
}; };
this._aria2.onclose = ()=>{ this._aria2.onclose = ()=> {
console.log('aria2 close'); console.log('aria2 close');
this.aria2IsOpen = false; this.aria2IsOpen = false;
}; };
this._aria2.onDownloadComplete = (response)=>{ this._aria2.onDownloadComplete = (response)=> {
console.log(response); console.log(response);
//aria2.tellStatus(tmp_gid, (err, res)=>{ //aria2.tellStatus(tmp_gid, (err, res)=>{
// if(res.followedBy) { // if(res.followedBy) {
...@@ -51,15 +52,15 @@ export class AppsService { ...@@ -51,15 +52,15 @@ export class AppsService {
// console.log(res); // console.log(res);
//}); //});
}; };
this._aria2.onmessage = (m)=>{ this._aria2.onmessage = (m)=> {
console.log('IN:', m); console.log('IN:', m);
console.log('download infoi:', this.downloadsInfo); console.log('download infoi:', this.downloadsInfo);
} }
} }
if(!this.aria2IsOpen) { if (!this.aria2IsOpen) {
this._aria2.open().then(()=>{ this._aria2.open().then(()=> {
console.log('aria2 websocket open') console.log('aria2 websocket open')
this.aria2IsOpen = true; this.aria2IsOpen = true;
}); });
...@@ -71,12 +72,12 @@ export class AppsService { ...@@ -71,12 +72,12 @@ export class AppsService {
_download_dir; _download_dir;
get download_dir() { get download_dir() {
const dir = this.path.join(this.electron.remote.app.getAppPath(), 'cache'); const dir = this.path.join(this.electron.remote.app.getAppPath(), 'cache');
if(!this.fs.existsSync(dir)) { if (!this.fs.existsSync(dir)) {
console.log('cache not exists'); console.log('cache not exists');
this.mkdirp(dir, (err)=>{ this.mkdirp(dir, (err)=> {
if(err) { if (err) {
console.error(err) console.error(err)
} else { } else {
console.log('create cache dir'); console.log('create cache dir');
...@@ -92,10 +93,21 @@ export class AppsService { ...@@ -92,10 +93,21 @@ export class AppsService {
.map(response => { .map(response => {
return response.json() return response.json()
}) })
.subscribe(data => { .subscribe((data) => {
this.data = data; this.data = data;
for (let app of data) {
//console.log(app)
for (let attribute of ['name', 'description']) {
if(!app[attribute]){continue} //这句应当是不需要的, 如果转换成了 App 类型, 应当保证一定有这些属性
for (let locale of Object.keys(app[attribute])) {
let result = {};
result[`app.${app['id']}.${attribute}`] = app[attribute][locale];
this.translate.setTranslation(locale, result, true);
}
}
}
//console.log(this.data); //console.log(this.data);
if(typeof(callback) === 'function') { if (typeof(callback) === 'function') {
callback(); callback();
} }
}); });
...@@ -106,7 +118,7 @@ export class AppsService { ...@@ -106,7 +118,7 @@ export class AppsService {
console.log(uri); console.log(uri);
let tmp_gid; let tmp_gid;
this.aria2.addUri([uri], {'dir': this.download_dir}, (error, gid)=> { this.aria2.addUri([uri], {'dir': this.download_dir}, (error, gid)=> {
if(error) { if (error) {
console.error(error); console.error(error);
} }
console.log(gid); console.log(gid);
......
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
</li> </li>
--> -->
<li [ngClass]="{active: routingService.component == 'lobby'}" class="nav-item"> <li [ngClass]="{active: routingService.component == 'lobby'}" class="nav-item">
<a (click)="changeFouce('lobby')" class="nav-link" href="#">游戏<span class="sr-only">(current)</span></a> <a (click)="changeFouce('lobby')" class="nav-link" href="#">{{'library'| translate}}<span class="sr-only">(current)</span></a>
</li> </li>
<li [ngClass]="{active: routingService.component == 'community'}" class="nav-item"> <li [ngClass]="{active: routingService.component == 'community'}" class="nav-item">
<a (click)="changeFouce('community')" class="nav-link" href="#">社区</a> <a (click)="changeFouce('community')" class="nav-link" href="#">{{'community'| translate}}</a>
</li> </li>
</ul> </ul>
<div class="navbar-right"> <div class="navbar-right">
......
import {Component, Renderer} from '@angular/core'; import {Component, Renderer} from '@angular/core';
declare var process; import {TranslateService} from 'ng2-translate/ng2-translate';
declare var System;
import {RoutingService} from './routing.service'; import {RoutingService} from './routing.service';
const electron = System._nodeRequire('electron'); const electron = System._nodeRequire('electron');
declare var process;
declare var System;
@Component({ @Component({
...@@ -15,16 +16,24 @@ const electron = System._nodeRequire('electron'); ...@@ -15,16 +16,24 @@ const electron = System._nodeRequire('electron');
export class MyCardComponent { export class MyCardComponent {
platform = process.platform; platform = process.platform;
constructor(private routingService: RoutingService, private renderer: Renderer) { constructor(private routingService: RoutingService, private renderer: Renderer, private translate: TranslateService) {
renderer.listenGlobal('window', 'message', (event) => { renderer.listenGlobal('window', 'message', (event) => {
console.log(event); console.log(event);
// Do something with 'event' // Do something with 'event'
}); });
// this language will be used as a fallback when a translation isn't found in the current language
translate.setDefaultLang('en-US');
// the lang to use, if the lang isn't available, it will use the current loader to get them
translate.use(electron.remote.app.getLocale());
} }
changeFouce(component) { changeFouce(component) {
this.routingService.component = component; this.routingService.component = component;
} }
refresh() { refresh() {
electron.remote.getCurrentWindow().reload() electron.remote.getCurrentWindow().reload()
} }
......
...@@ -15,8 +15,10 @@ import {CommunityComponent} from './community.component'; ...@@ -15,8 +15,10 @@ import {CommunityComponent} from './community.component';
import {RoutingService} from './routing.service'; import {RoutingService} from './routing.service';
import {AppsService} from './apps.service'; import {AppsService} from './apps.service';
import {TranslateModule} from 'ng2-translate/ng2-translate';
@NgModule({ @NgModule({
imports: [BrowserModule, HttpModule], imports: [BrowserModule, HttpModule, TranslateModule.forRoot()],
declarations: [MyCardComponent, LoginComponent, StoreComponent, LobbyComponent, CommunityComponent, AppsComponent, AppDetailComponent, RosterComponent, CandyComponent], declarations: [MyCardComponent, LoginComponent, StoreComponent, LobbyComponent, CommunityComponent, AppsComponent, AppDetailComponent, RosterComponent, CandyComponent],
bootstrap: [MyCardComponent], bootstrap: [MyCardComponent],
providers: [RoutingService, AppsService], providers: [RoutingService, AppsService],
......
{
"library": "游戏",
"community": "社区"
}
...@@ -2,47 +2,51 @@ ...@@ -2,47 +2,51 @@
* System configuration for Angular 2 samples * System configuration for Angular 2 samples
* Adjust as necessary for your application needs. * Adjust as necessary for your application needs.
*/ */
(function(global) { (function (global) {
// map tells the System loader where to look for things // map tells the System loader where to look for things
var map = { var map = {
'app': 'app', // 'dist', 'app': 'app', // 'dist',
'@angular': 'node_modules/@angular', '@angular': 'node_modules/@angular',
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api', 'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'rxjs': 'node_modules/rxjs' 'rxjs': 'node_modules/rxjs',
}; 'ng2-translate': 'node_modules/ng2-translate',
// packages tells the System loader how to load when no filename and/or no extension };
var packages = { // packages tells the System loader how to load when no filename and/or no extension
'app': { main: 'main.js', defaultExtension: 'js' }, var packages = {
'rxjs': { defaultExtension: 'js' }, 'app': {main: 'main.js', defaultExtension: 'js'},
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' }, 'rxjs': {defaultExtension: 'js'},
}; 'angular2-in-memory-web-api': {main: 'index.js', defaultExtension: 'js'},
var ngPackageNames = [ 'ng2-translate': {main: 'ng2-translate.js', defaultExtension: 'js'},
'common', };
'compiler', var ngPackageNames = [
'core', 'common',
'forms', 'compiler',
'http', 'core',
'platform-browser', 'forms',
'platform-browser-dynamic', 'http',
'router', 'platform-browser',
'router-deprecated', 'platform-browser-dynamic',
'upgrade', 'router',
]; 'router-deprecated',
// Individual files (~300 requests): 'upgrade',
function packIndex(pkgName) { ];
packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' }; // Individual files (~300 requests):
} function packIndex(pkgName) {
// Bundled (~40 requests): packages['@angular/' + pkgName] = {main: 'index.js', defaultExtension: 'js'};
function packUmd(pkgName) { }
packages['@angular/'+pkgName] = { main: 'bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };
} // Bundled (~40 requests):
// Most environments should use UMD; some (Karma) need the individual index files function packUmd(pkgName) {
var setPackageConfig = System.packageWithIndex ? packIndex : packUmd; packages['@angular/' + pkgName] = {main: 'bundles/' + pkgName + '.umd.js', defaultExtension: 'js'};
// Add package entries for angular packages }
ngPackageNames.forEach(setPackageConfig);
var config = { // Most environments should use UMD; some (Karma) need the individual index files
map: map, var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;
packages: packages // Add package entries for angular packages
}; ngPackageNames.forEach(setPackageConfig);
System.config(config); var config = {
map: map,
packages: packages
};
System.config(config);
})(this); })(this);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment