Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
common
Overview
Overview
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
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
npm
common
Commits
5870a612
Commit
5870a612
authored
Oct 29, 2018
by
Vladislav Lagunov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[gettext] Добавлен пример использования
parent
8d6c9b27
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
1 deletions
+40
-1
gettext/README.md
+40
-1
No files found.
gettext/README.md
View file @
5870a612
## Пример использования
## Пример использования
TODO
```
ts
import
{
makeGettext
,
withGettext
,
I18nString
}
from
'~/gettext'
;
const
gettext
=
makeGettext
(
require
(
'./i18n.po.yml'
));
// Отложенный перевод строк
function
printStatus
(
status
:
'buzy'
|
'idle'
):
I18nString
{
switch
(
status
)
{
case
'buzy'
:
return
gettext
(
'Buzy'
);
case
'idle'
:
return
gettext
(
'Idle'
);
}
}
// Тип I18nString
// type I18nString = (locale?: string|LocaleCtx|null) => string;
// те функция, которая вернет строку если ей передать нужную локаль
console
.
log
(
printStatus
(
'buzy'
)(
'ru-RU'
));
// => 'Занят'
// Эти поля должны присутствовать в `Props` для использования `withGettext`
export
type
Props
=
{
__
:
Gettext
;
ctx
:
LocaleCtx
;
};
class
Widget
extends
React
.
Component
<
Props
>
{
render
()
{
const
{
__
}
=
this
.
props
;
return
<
div
>
{
__
(
'Hello, World!'
)}
<
/div>
;
}
}
export
default
withGettext
(
gettext
)(
Widget
);
// Или так
// export default withGettext(require('./i18n.po.yml'))(Widget);
```
## Формат *.po.yml
## Формат *.po.yml
...
...
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