forked from steemit/condenser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first merge: very preleminary and needs testing
- Loading branch information
valzav
committed
Nov 6, 2016
1 parent
36e9488
commit 9af137b
Showing
83 changed files
with
2,494 additions
and
795 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,19 @@ import React from 'react'; | |
import isString from 'lodash/isString'; | ||
import isObject from 'lodash/isObject'; | ||
import isUndefined from 'lodash/isUndefined'; | ||
import { connect } from 'react-redux' | ||
import { IntlProvider, addLocaleData, injectIntl } from 'react-intl'; | ||
import store from 'store'; | ||
import { DEFAULT_LANGUAGE } from 'config/client_config'; | ||
|
||
// most of this code creates a wrapper for i18n API. | ||
// this is needed to make i18n future proof | ||
|
||
/* | ||
module exports two functions: translate and translateHtml | ||
usage example: | ||
translate('reply_to_user', {username: 'undeadlol1') == 'Reply to undeadlol1' | ||
translateHtml works the same, expcept it renders string with html tags in it | ||
module exports two functions: translate and translateHtml | ||
usage example: | ||
translate('reply_to_user', {username: 'undeadlol1') == 'Reply to undeadlol1' | ||
translateHtml works the same, expcept it renders string with html tags in it | ||
*/ | ||
|
||
// locale data is needed for various messages, ie 'N minutes ago' | ||
|
@@ -28,7 +31,7 @@ import { ru } from './locales/ru'; | |
import { fr } from './locales/fr'; | ||
import { es } from './locales/es'; | ||
import { it } from './locales/it'; | ||
const translations = { | ||
const messages = { | ||
en: en, | ||
ru: ru, | ||
fr: fr, | ||
|
@@ -38,9 +41,18 @@ const translations = { | |
|
||
// exported function placeholders | ||
// this is needed for proper export before react-intl functions with locale data, | ||
// will be properly created (they depend on react props and context, | ||
// which is not available until component is being created) | ||
let translate = () => {}; | ||
// will be properly created (they depend on react props and context), | ||
// which is not available until component is being created | ||
// | ||
/* | ||
this placeholder is needed for usage outside of react. In server side code and in static html files. | ||
This function is very simple, it does NOT support dynamic values (for example: translate('your_email_is', {email: '[email protected]'})). Use it carefully | ||
*/ | ||
let translate = string => { | ||
let language = DEFAULT_LANGUAGE | ||
if (process.env.BROWSER) language = store.get('language') || DEFAULT_LANGUAGE | ||
return messages[language][string] | ||
}; | ||
let translateHtml = () => {}; | ||
let translatePlural = () => {}; | ||
|
||
|
@@ -105,24 +117,30 @@ class Translator extends React.Component { | |
// Define user's language. Different browsers have the user locale defined | ||
// on different fields on the `navigator` object, so we make sure to account | ||
// for these different by checking all of them | ||
let language = 'en'; | ||
// while Server Side Rendering is in process, 'navigator' is undefined | ||
let language = this.props.locale; // usually 'en' | ||
if (process.env.BROWSER) { | ||
language = navigator ? (navigator.languages && navigator.languages[0]) | ||
|| navigator.language | ||
|| navigator.userLanguage | ||
: 'en'; | ||
const storredLanguage = store.get('language') | ||
if (storredLanguage) language = storredLanguage | ||
} | ||
|
||
//Split locales with a region code (ie. 'en-EN' to 'en') | ||
const languageWithoutRegionCode = language.toLowerCase().split(/[_-]+/)[0]; | ||
|
||
// TODO: don't forget to add Safari polyfill | ||
|
||
// to ensure dynamic language change, "key" property with same "locale" info must be added | ||
// see: https://github.com/yahoo/react-intl/wiki/Components#multiple-intl-contexts | ||
let messages = translations[languageWithoutRegionCode] | ||
return <IntlProvider locale={languageWithoutRegionCode} key={languageWithoutRegionCode} messages={messages}> | ||
// let language = DEFAULT_LANGUAGE; // usually 'en' | ||
// while Server Side Rendering is in process, 'navigator' is undefined | ||
// currently commented out, because in golos we need only russian | ||
// if (process.env.BROWSER) language = navigator | ||
// ? (navigator.languages && navigator.languages[0]) | ||
// || navigator.language | ||
// || navigator.userLanguage | ||
// : DEFAULT_LANGUAGE; | ||
//Split locales with a region code (ie. 'en-EN' to 'en') | ||
const languageWithoutRegionCode = language.toLowerCase().split(/[_-]+/)[0]; | ||
|
||
return <IntlProvider | ||
// to ensure dynamic language change, "key" property with same "locale" info must be added | ||
// see: https://github.com/yahoo/react-intl/wiki/Components#multiple-intl-contexts | ||
key={languageWithoutRegionCode} | ||
defaultLocale={DEFAULT_LANGUAGE} | ||
locale={languageWithoutRegionCode} | ||
messages={messages[languageWithoutRegionCode]} | ||
> | ||
<div> | ||
<DummyComponentToExportProps /> | ||
{this.props.children} | ||
|
@@ -133,4 +151,13 @@ class Translator extends React.Component { | |
|
||
export { translate, translateHtml, translatePlural } | ||
|
||
export default Translator | ||
export default connect( | ||
// mapStateToProps | ||
(state, ownProps) => { | ||
const locale = state.user.get('locale') | ||
return { | ||
...ownProps, | ||
locale | ||
} | ||
} | ||
)(Translator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<browserconfig> | ||
<msapplication> | ||
<tile> | ||
<square150x150logo src="/images/favicons/mstile-150x150.png"/> | ||
<TileColor>#ffffff</TileColor> | ||
</tile> | ||
</msapplication> | ||
</browserconfig> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "Golos", | ||
"icons": [ | ||
{ | ||
"src": "\/images\/favicons\/android-chrome-192x192.png", | ||
"sizes": "192x192", | ||
"type": "image\/png" | ||
}, | ||
{ | ||
"src": "\/images\/favicons\/android-chrome-512x512.png", | ||
"sizes": "512x512", | ||
"type": "image\/png" | ||
} | ||
], | ||
"theme_color": "#ffffff", | ||
"display": "standalone" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React, { Component } from 'react'; | ||
import { Field, reduxForm } from 'redux-form'; | ||
|
||
// change it field by field | ||
class ChangeAccountMeta extends Component { | ||
render() { | ||
const { handleSubmit } = this.props; | ||
return ( | ||
<form onSubmit={handleSubmit}> | ||
<div> | ||
<label htmlFor="metaKey">meta key</label> | ||
<Field name="metaKey" component="input" type="text"/> | ||
</div> | ||
<div> | ||
<label htmlFor="metaValue">meta value</label> | ||
<Field name="metaValue" component="input" type="email"/> | ||
</div> | ||
<div> | ||
<label htmlFor="passord">First Name</label> | ||
<Field name="password" component="input" type="password"/> | ||
</div> | ||
<button type="submit">Submit</button> | ||
</form> | ||
); | ||
} | ||
} | ||
|
||
// Decorate the form component | ||
ChangeAccountMeta = reduxForm({ | ||
form: 'changeAccountMeta' // a unique name for this form | ||
})(ChangeAccountMeta); |
Oops, something went wrong.