Skip to content

Commit 4e275d7

Browse files
committed
add provider docs
1 parent cb69248 commit 4e275d7

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,91 @@ Infuse the meta of locale messages to i18n custom block at single-file component
156156

157157
`infuse` function will return new single-file components information that is updated with the single-file components information specified as `sources` and the meta of locale message as `meta`.
158158

159+
## :book: Provider: Specifications
160+
161+
You can use the `push` or `pull` commands to push the locale message to the l10n service as a resource for that service, and also to pull resources from the l10n service as the locale message.
162+
163+
<p align="center"><img src="./assets/push-pull-command-image.png" alt="Push and Pull Image"></p>
164+
165+
When you run `push` or `pull` commands, you need the provider that implements the following.
166+
167+
- export provider factory function
168+
- provider factory function must return a provider object that have the following I/F:
169+
- `push` method
170+
- `pull` method
171+
172+
The type definition with TypeScript is as follows:
173+
174+
```ts
175+
/**
176+
* Provider factory function
177+
*/
178+
type ProviderFactory<T = {}> = (configration: ProviderConfiguration<T>) => Provider
179+
180+
/**
181+
* Provider interface
182+
*/
183+
interface Provider {
184+
/**
185+
* push the resource to localization service
186+
* @param resource the resource that push to localization service
187+
* @param dryRun whether the CLI run as dryRun mode
188+
*/
189+
push (resource: ProviderPushResource, dryRun: boolean): Promise<void>
190+
/**
191+
* pull the resource from localization service
192+
* @param locales locales that pull from localization service, if empty, you must pull the all locale messages
193+
* @param dryRun whether the CLI run as dryRun mode
194+
* @returns the resource of localization service
195+
*/
196+
pull (locales: Locale[], dryRun: boolean): Promise<ProviderPullResource>
197+
}
198+
199+
/**
200+
* mode that can be processed with provider push
201+
* - 'file-path':
202+
* To use when the provider uses the locale message directly from the file.
203+
* for example, used for file uploading.
204+
* When specified that mode, `ProviderPushResource` are passed from the CLI as `files`.
205+
* - 'locale-message':
206+
* To use when the provider uses the locale message.
207+
* When specified that mode, `ProviderPushResource` are passed from the CLI as `messaegs`.
208+
*/
209+
type ProviderPushMode = 'file-path' | 'locale-message'
210+
211+
type ProviderPushFileInfo = {
212+
locale: Locale
213+
path: string
214+
}
215+
216+
type ProviderPushResource = {
217+
mode: ProviderPushMode
218+
files?: ProviderPushFileInfo[]
219+
messages?: LocaleMessages
220+
}
221+
222+
type ProviderPullResource = LocaleMessages
223+
224+
/**
225+
* ProviderConfiguration provider fields structure
226+
* e.g.
227+
* {
228+
* "provider": {
229+
* "token": "xxx"
230+
* },
231+
* "pushMode": "file-path"
232+
* }
233+
*/
234+
interface ProviderConfiguration<T = {}> {
235+
provider: { [key in keyof ProviderConfigurationValue<T>]: ProviderConfigurationValue<T>[key] }
236+
pushMode: ProviderPushMode
237+
}
238+
239+
type ProviderConfigurationValue<T = {}> = T & { [prop: string]: unknown }
240+
```
241+
242+
As an implementation example of Provider, there is [`poeditor-service-provider`](https://github.com/kazupon/poeditor-service-provider) implemented as localization service provider of poeditor.
243+
159244
## :notebook: CLI: Locale message squeezing rules
160245
161246
The structure of locale messages to be squeezed is layered with the **directory structure** and **single-file component (`.vue`) filename**.

assets/push-pull-command-image.png

50.9 KB
Loading

0 commit comments

Comments
 (0)