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
8d6c9b27
Commit
8d6c9b27
authored
Oct 29, 2018
by
Vladislav Lagunov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[gettext] Добавлен gettext/README.md
parent
0c4f7dae
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
4 deletions
+68
-4
gettext/README.md
+64
-0
gettext/index.ts
+4
-4
No files found.
gettext/README.md
0 → 100644
View file @
8d6c9b27
## Пример использования
TODO
## Формат *.po.yml
Альтернативный формат, для
*
.po файлов предназначен предназначен для
более простой манипуляции с gettext-данными, и для обеспечения
возможности хранения переводов вместе с UI-компонентами модуль
```yml
- "":
locale: "ru-RU"
"Accommodations": "Проживания"
"Select guests": "Выберите гостя"
"%podata":
- msgid: "%d sec"
msgid_plural: "%d sec"
msgstr: ["%d секунда", "%d секунды", "%d секунд"]
- msgid: "<b>%d</b>–<b>%d</b> of <b>%d</b>"
msgid_plural: "<b>%d</b>–<b>%d</b> of <b>%d</b>"
msgstr: ["<b>%d</b>–<b>%d</b> из <b>%d</b>", "<b>%d</b>–<b>%d</b> из <b>%d</b>", "<b>%d</b>–<b>%d</b> из <b>%d</b>" ]
```
В корне
*
.po.yml должен быть массив, каждый элемент которого
соответствует целому
*
.po файлу.
```
- "":
locale: "ru-RU"
```
в поле с пустым именем содержатся метаданные файла (как в секции msgid
"" в оригинальном
*
.po)
```
"%podata":
- msgid: "%d sec"
msgid_plural: "%d sec"
msgstr: ["%d секунда", "%d секунды", "%d секунд"]
```
Еще одно специальное поле в объекте внутри массива —
`%podata`
внутри
содержатся поля соответствующие записям из оригинального формата po
`msgid`
,
`msgid_plural`
,
`msgctx`
,
`msgstr`
```
- ""
# ...
"Accommodations": "Проживания"
"Select guests": "Выберите гостя"
# Тоже самое в *.po
msgid "Accommodations"
msgstr "Проживания"
msgid "Select guests"
msgstr "Выберите гостя"
```
Остальные ключи внутри эелемента в корне массива соответствуют краткой
форме для записи в po в которой присутствуют только две строки
`msgid`
и
`msgstr`
gettext/index.ts
View file @
8d6c9b27
...
...
@@ -11,13 +11,13 @@ const CONTEXT_DELIMITER = String.fromCharCode(4);
export
type
Translations
=
Record
<
string
,
Record
<
string
,
string
[]
|
string
>>
;
export
type
GettextData
=
{
''
:
Record
<
string
,
unknown
>
;
'%
explicit
'
:
GettextExplicitKey
[],
'%
podata
'
:
GettextExplicitKey
[],
}
&
{
[
K
in
string
]:
string
|
string
[];
};
// Содержимое поля `%
explicit
`
// Содержимое поля `%
podata
`
export
type
GettextExplicitKey
=
{
msgid
:
string
;
msgid_plural
?:
string
;
...
...
@@ -121,9 +121,9 @@ export function requireTranslations(webpackContext /*: WebpackContext*/): Transl
function
assignData
(
dst
:
Translations
,
...
srcs
:
GettextData
[]):
Translations
{
srcs
.
forEach
(
data
=>
{
const
locale
=
data
[
''
].
locale
;
if
(
!
locale
||
typeof
(
locale
)
!==
'string'
)
return
;
const
explicitKeys
=
data
[
'%
explicit
'
];
const
explicitKeys
=
data
[
'%
podata
'
];
for
(
const
k
of
Object
.
keys
(
data
))
{
if
(
k
===
''
||
k
===
'%
explicit
'
)
continue
;
if
(
k
===
''
||
k
===
'%
podata
'
)
continue
;
dst
[
locale
]
=
dst
[
locale
]
||
{};
dst
[
locale
][
k
]
=
data
[
k
];
}
...
...
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