Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
retypos-webclient
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
eterfund
retypos-webclient
Commits
f96413d1
Commit
f96413d1
authored
Jul 04, 2018
by
Георгий Попов
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add working i18n to the app. Add custom lang switching component
parent
d6e80ffa
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
134 additions
and
9 deletions
+134
-9
ContextExtractor.js
src/App/ContextExtractor.js
+4
-0
icon_english.png
src/LangSwitcher/images/icon_english.png
+0
-0
icon_russian.png
src/LangSwitcher/images/icon_russian.png
+0
-0
index.js
src/LangSwitcher/images/index.js
+10
-0
index.js
src/LangSwitcher/index.js
+52
-0
styles.css
src/LangSwitcher/styles.css
+17
-0
Localization.js
src/Localization.js
+20
-2
Modal.css
src/Modal/Modal.css
+10
-0
index.js
src/Modal/index.js
+19
-6
config.js
src/config.js
+2
-1
No files found.
src/App/ContextExtractor.js
View file @
f96413d1
...
...
@@ -8,6 +8,10 @@ export default class ContextExtractor {
// Returns a context for a current selection
getContextForSelection
()
{
if
(
window
.
getSelection
().
baseNode
===
undefined
)
{
return
""
;
}
const
text
=
window
.
getSelection
()
.
baseNode
.
parentNode
.
textContent
.
replace
(
/
\n
/g
,
""
)
...
...
src/LangSwitcher/images/icon_english.png
0 → 100644
View file @
f96413d1
1.38 KB
src/LangSwitcher/images/icon_russian.png
0 → 100644
View file @
f96413d1
245 Bytes
src/LangSwitcher/images/index.js
0 → 100644
View file @
f96413d1
import
ruImage
from
'./icon_russian.png'
;
import
enImage
from
'./icon_english.png'
;
const
countryImages
=
{
ru
:
ruImage
,
en
:
enImage
,
};
export
default
countryImages
;
\ No newline at end of file
src/LangSwitcher/index.js
0 → 100644
View file @
f96413d1
import
React
,
{
Component
}
from
'react'
import
{
Thumbnail
}
from
'react-bootstrap'
import
{
i18n
}
from
'../Localization'
;
import
{
config
}
from
'../config'
;
import
countryImages
from
'./images'
;
import
'./styles.css'
class
LangSwitcher
extends
Component
{
constructor
(
props
,
context
)
{
super
(
props
,
context
);
this
.
languages
=
[];
this
.
languages
=
props
.
languages
;
this
.
onLangChanged
=
props
.
onLangChanged
;
this
.
state
=
{
activeLanguage
:
0
};
}
changeLanguage
=
index
=>
{
this
.
setState
({
activeLanguage
:
index
});
this
.
onLangChanged
(
this
.
languages
[
index
]);
}
render
()
{
const
thumbs
=
this
.
languages
.
map
((
element
,
index
)
=>
{
if
(
index
===
this
.
state
.
activeLanguage
)
{
return
<
Thumbnail
key
=
{
index
}
className
=
"lang-thumb active"
src
=
{
countryImages
[
element
]}
onClick
=
{
e
=>
this
.
changeLanguage
(
index
)}
><
/Thumbnail
>
}
else
{
return
<
Thumbnail
key
=
{
index
}
className
=
"lang-thumb"
src
=
{
countryImages
[
element
]}
onClick
=
{
e
=>
this
.
changeLanguage
(
index
)}
><
/Thumbnail
>
}
});
return
(
<
div
className
=
"lang-switcher"
>
{
thumbs
}
<
/div
>
);
}
}
export
default
LangSwitcher
;
\ No newline at end of file
src/LangSwitcher/styles.css
0 → 100644
View file @
f96413d1
.lang-switcher
{
display
:
inline-block
;
}
.lang-thumb
{
display
:
inline-block
;
margin
:
0
;
}
.lang-thumb.active
{
background
:
#5cb85c
;
}
.lang-thumb
:hover:not
(
.active
)
{
background
:
rgba
(
92
,
184
,
92
,
0.59
);
}
\ No newline at end of file
src/Localization.js
View file @
f96413d1
...
...
@@ -17,9 +17,26 @@ export const i18n = new LocalizedStrings({
close
:
"Закрыть"
,
saveChanges
:
"Сохранить изменения"
,
messageSuccess
:
"Благодарим за отправку опечатки. Мы уже работаем над её исправлением!"
,
messageFailture
:
"Не удалось отправить исправление. Мы уже работаем над решением проблемы!"
,
errorFormContainsErrors
:
"Форма отправки содержит ошибки!"
,
errorSendFailture
:
"Не удалось отправить исправление. Мы уже работаем над решением проблемы!"
,
},
en
:
{
modalTitle
:
"Typo correction system Etersoft"
,
modalInfo
:
"Please, type in a correct variant to the input field bellow and optional commentary. Than press the send button "
+
"to send the correction to the server."
,
modalCorrectLabel
:
"Corrected text"
,
modalCorrectHelp
:
"Moderators will check your proposal corretion and fix it!"
,
modalTypoLabel
:
"The typo"
,
modalCommentPlaceholder
:
`"A typo", for example`
,
modalCommentLabel
:
"Commentary"
,
errorSelectionLength
:
"The text length must be in range ({0}-{1})"
,
errorCorrectLength
:
"The corrected text length must be in range ({0}-{1})"
,
errorDoesNotDistinct
:
"The original and corrected text are the same"
,
errorTooOften
:
"You are sending correction requests too often"
,
close
:
"Close"
,
saveChanges
:
"Save changes"
,
messageSuccess
:
"Thank you for a typo submitting! We are already working on this report!"
,
errorFormContainsErrors
:
"The form contains errors!"
,
errorSendFailture
:
"Failed to send request. We are fixing a problem!"
,
}
})
\ No newline at end of file
src/Modal/Modal.css
View file @
f96413d1
...
...
@@ -9,4 +9,13 @@
.es-typo-text-fg
{
margin-top
:
30px
;
}
.ru-lang-thumb
,
.en-lang-thumb
{
float
:
left
;
width
:
50px
;
}
.lang-switcher
{
float
:
left
;
}
\ No newline at end of file
src/Modal/index.js
View file @
f96413d1
import
React
,
{
Component
}
from
'react'
;
import
{
Modal
,
Button
,
FormGroup
,
FormControl
,
ControlLabel
,
HelpBlock
,
Alert
}
from
'react-bootstrap'
import
{
Modal
,
Button
,
FormGroup
,
FormControl
,
ControlLabel
,
HelpBlock
,
Alert
,
Thumbnail
}
from
'react-bootstrap'
import
$
from
'jquery'
;
import
'./Modal.css'
;
...
...
@@ -7,6 +7,8 @@ import './Modal.css';
import
{
i18n
}
from
'../Localization'
;
import
{
config
}
from
'../config'
;
import
LangSwitcher
from
'../LangSwitcher'
;
const
alertify
=
require
(
"alertify.js"
);
class
TypoModal
extends
Component
{
...
...
@@ -19,12 +21,15 @@ class TypoModal extends Component {
text
:
this
.
props
.
text
,
correct
:
this
.
props
.
text
,
context
:
this
.
props
.
context
,
language
:
config
.
defaultLanguage
,
comment
:
""
,
error
:
""
}
this
.
languages
=
[
"ru"
,
"en"
];
// TODO: English support
i18n
.
setLanguage
(
config
.
language
);
i18n
.
setLanguage
(
this
.
state
.
language
);
this
.
closeCallback
=
props
.
closeCallback
;
...
...
@@ -84,7 +89,7 @@ class TypoModal extends Component {
"https://test.etersoft.ru/test_react_client"
;
const
data
=
{
language
:
config
.
language
,
language
:
this
.
state
.
language
,
// Url of the page with a typo
url
:
url
,
...
...
@@ -126,7 +131,7 @@ class TypoModal extends Component {
async
submitTypo
(
corrected
,
comment
)
{
if
(
!
this
.
checkData
())
{
alertify
.
error
(
i18n
.
messageFailture
);
alertify
.
error
(
i18n
.
errorFormContainsErrors
);
return
;
}
...
...
@@ -140,10 +145,16 @@ class TypoModal extends Component {
return
;
}
alertify
.
error
(
i18n
.
message
Failture
);
alertify
.
error
(
i18n
.
errorSend
Failture
);
});
}
onLangChanged
=
language
=>
{
i18n
.
setLanguage
(
language
);
this
.
setState
({
language
:
language
});
this
.
forceUpdate
();
}
render
()
{
if
(
!
this
.
state
.
show
)
return
null
;
...
...
@@ -178,10 +189,12 @@ class TypoModal extends Component {
<
/FormGroup
>
<
/form
>
{
this
.
state
.
error
?
<
Alert
bsStyle
=
"danger"
>
{
this
.
state
.
error
}
<
/Alert> : null
}
{
this
.
state
.
error
&&
<
Alert
bsStyle
=
"danger"
>
{
this
.
state
.
error
}
<
/Alert>
}
<
/Modal.Body
>
<
Modal
.
Footer
>
<
LangSwitcher
onLangChanged
=
{
this
.
onLangChanged
}
languages
=
{
this
.
languages
}
><
/LangSwitcher
>
<
Button
onClick
=
{
this
.
handleClose
}
>
{
i18n
.
close
}
<
/Button
>
<
Button
onClick
=
{
this
.
submitTypo
}
bsStyle
=
"primary"
>
{
i18n
.
saveChanges
}
<
/Button
>
<
/Modal.Footer
>
...
...
src/config.js
View file @
f96413d1
...
...
@@ -9,5 +9,5 @@ export const config = {
requestTimeout
:
10000
,
language
:
"ru"
,
defaultLanguage
:
"ru"
,
};
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment