Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Codecrew
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
30
Merge Requests
2
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 396250da
authored
Apr 01, 2018
by
Tuukka Kivilahti
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/i18n-for-angular' of gitlab.codecrew.fi:codecrew/moya into…
… feature/i18n-for-angular
2 parents
3e5da1d0
05a1b193
Pipeline
#39
running
in 0 seconds
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
31 deletions
code/moya-angular/src/app/components/moya-locale/moya-locale.component.ts
code/moya-angular/src/app/components/moya-locale/moya-locale.model.ts
code/moya-angular/src/app/components/moya-locale/moya-locale.service.ts
code/moya-angular/src/app/components/moya-locale/moya-locale.component.ts
View file @
396250d
...
...
@@ -2,13 +2,10 @@ import { Component, OnInit } from '@angular/core';
import
{
DEFAULT_LOCALE
,
MoyaLocaleService
}
from
'./moya-locale.service'
;
import
{
TranslateService
}
from
'@ngx-translate/core'
;
const
ENGLISH
=
'en'
;
const
FINNISH
=
'fi'
;
const
SWEDISH
=
'sv'
;
@
Component
({
selector
:
'moya-locale'
,
templateUrl
:
'./moya-locale.component.html'
,
...
...
@@ -30,7 +27,6 @@ export class MoyaLocaleComponent implements OnInit {
this
.
localeService
.
getUserLocale
().
subscribe
(
locale
=>
{
this
.
selectLocale
(
locale
);
}
);
}
selectLocale
(
locale
:
string
,
save
=
false
):
void
{
if
(
!
[
ENGLISH
,
FINNISH
,
SWEDISH
].
includes
(
locale
))
{
...
...
@@ -59,7 +55,6 @@ export class MoyaLocaleComponent implements OnInit {
}
selectEnglish
()
{
this
.
selectLocale
(
ENGLISH
,
true
);
}
...
...
@@ -71,8 +66,4 @@ export class MoyaLocaleComponent implements OnInit {
selectSwedish
()
{
this
.
selectLocale
(
SWEDISH
,
true
);
}
}
code/moya-angular/src/app/components/moya-locale/moya-locale.model.ts
View file @
396250d
export
class
MoyaLocale
{
public
userLocale
?:
string
;
public
eventLocale
?:
string
;
constructor
()
{
}
export
interface
MoyaLocale
{
userLocale
:
string
;
eventLocale
:
string
;
}
code/moya-angular/src/app/components/moya-locale/moya-locale.service.ts
View file @
396250d
...
...
@@ -8,14 +8,10 @@ import 'rxjs/add/operator/catch';
export
const
DEFAULT_LOCALE
=
'fi'
;
const
LOCALSTORAGE_NAME
=
'currently used locale code'
;
@
Injectable
()
export
class
MoyaLocaleService
{
constructor
(
private
http
:
HttpClient
)
{
}
/**
* Order of Locale:
* 1. User's locale from database
...
...
@@ -27,8 +23,9 @@ export class MoyaLocaleService {
*/
public
getUserLocale
():
Observable
<
string
>
{
return
this
.
http
.
get
<
MoyaLocale
>
(
MOYA_BASE_URL
+
'/v3/locale/'
).
catch
(
x
=>
Observable
.
of
(
new
MoyaLocale
())).
map
(
locale
=>
{
return
this
.
http
.
get
<
MoyaLocale
>
(
MOYA_BASE_URL
+
'/v3/locale/'
)
.
catch
(
x
=>
Observable
.
of
({}
as
MoyaLocale
))
.
map
(
locale
=>
{
if
(
locale
&&
locale
.
userLocale
)
{
return
locale
.
userLocale
;
}
...
...
@@ -53,20 +50,18 @@ export class MoyaLocaleService {
*
* There is no errors
* @param {string} locale
* @return {Promise<any>} This will return promise, but it will contain nothing.
*/
public
setUserLocale
(
locale
:
string
):
void
{
const
newLocale
:
MoyaLocale
=
new
MoyaLocale
();
newLocale
.
userLocale
=
locale
;
const
newLocale
:
MoyaLocale
=
{
userLocale
:
locale
,
eventLocale
:
undefined
};
// let's save locale to database, if it fails, we save it into localstorage. No errors to show for user.
this
.
http
.
post
(
MOYA_BASE_URL
+
'/v3/locale/'
,
newLocale
).
first
().
catch
(
x
=>
{
this
.
http
.
post
(
MOYA_BASE_URL
+
'/v3/locale/'
,
newLocale
).
catch
(
x
=>
{
localStorage
.
setItem
(
LOCALSTORAGE_NAME
,
locale
);
return
'ok'
;
}).
subscribe
();
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment