@deriv-com/translations 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +37 -18
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -30,6 +30,23 @@ base_url is the cdnUrl passed to the `initializeI18n` function, and lang is the
30
30
 
31
31
  ## Getting Started
32
32
 
33
+ To get started, one would need few things to setup first which are:
34
+ 1. A Crowdin project which will be used to manage translations for your project.
35
+ 2. A Cloudflare R2 account to store the translations.
36
+ - Create a new bucket in the R2 account.
37
+ - Create a new access key in the R2 account.
38
+ 3. Add the following secrets to your repository:
39
+ - `CROWDIN_PROJECT_ID`: Open your crowdin project and navigate to `Tools` tab, you will be able to get the Project ID, store that in your github secrets.
40
+ - `CROWDIN_PERSONAL_TOKEN`: This can be obtained by logging in to your crowdin account and clicking on your profile icon and goto `Settings > API` and create a new personal access token, store that in your github secrets.
41
+ - `R2_ACCOUNT_ID`: R2 account ID from the Cloudflare R2 dashboard.
42
+ - `R2_ACCESS_KEY_ID`: R2 access key ID from the Cloudflare R2 dashboard.
43
+ - `R2_SECRET_ACCESS_KEY`: R2 secret access key from the Cloudflare R2 dashboard.
44
+ - `R2_BUCKET_NAME`: R2 bucket name from the Cloudflare R2 dashboard.
45
+ 4. Add the following environment variable in your repository:
46
+ - `PROJECT_NAME`: Add project name in your environment variable which will be used for Cloudflare R2 folder name for translations.
47
+ - `CROWDIN_BRANCH_NAME`: Add the branch name for your crowdin project to separate the translations based on environment, this needs to be put into the environment variable instead of secret because the consumer of the package needs it while defining the `cdnUrl` to access the translations.
48
+ 5. Setup the github action to sync the translations to the CDN, refer to the [Syncing translations](#syncing-translations) section for more details.
49
+
33
50
  Install the package by running:
34
51
 
35
52
  ```bash
@@ -38,7 +55,7 @@ npm install @deriv-com/translations
38
55
 
39
56
  ### Setup
40
57
 
41
- - initialize translations in main component by importing and calling `initializeI18n` outside of the component function
58
+ - initialize translations in main component by importing and calling `initializeI18n` outside of the component function.
42
59
  - pass the return value to the `TranslationProvider` component from `@deriv-com/translations`.
43
60
  - pass default language to the `TranslationProvider` component.
44
61
 
@@ -70,7 +87,7 @@ import initializeI18n from "@deriv-com/translations";
70
87
  initializeI18n({ cdnUrl: "https://cdn.example.com" });
71
88
  ```
72
89
 
73
- - For strings use either `localize(...)` or `<Localize />`
90
+ - For strings use either `localize(...)` or `<Localize />`.
74
91
 
75
92
  ### `Localize` component example:
76
93
 
@@ -102,7 +119,7 @@ The useTranslations hook is a custom hook that adds some more returned values on
102
119
  Example usage:
103
120
 
104
121
  ```javascript
105
- import { useTranslations } from "@deriv-com/package";
122
+ import { useTranslations } from "@deriv-com/translations";
106
123
 
107
124
  const MyComponent = () => {
108
125
  const { localize, switchLanguage, currentLang } = useTranslations();
@@ -121,21 +138,23 @@ There is a github action that syncs the translations from Crowdin to the CDN.
121
138
 
122
139
  The action takes following inputs:
123
140
 
124
- - `PROJECT_SOURCE_DIRECTORY`: Source directory of your project by default it is `src`
125
- - `CROWDIN_BASE_PATH`: Base path of the translations in the Crowdin project by default it is `.`
126
- - `CROWDIN_BASE_URL`: Base URL of the CDN where the translations are stored, default is `https://api.crowdin.com`
127
- - `CROWDIN_BRANCH_NAME`: Running on production, test or staging etc
128
- - `CROWDIN_PROJECT_ID`: Crowdin project ID which can be found in the crowdin project settings
129
- - `CROWDIN_PERSONAL_TOKEN`: Crowdin personal token which can be found in the crowdin account settings
130
- - `R2_ACCOUNT_ID`: R2 account ID from the Cloudflare R2 dashboard
131
- - `R2_ACCESS_KEY_ID`: R2 access key ID from the Cloudflare R2 dashboard
132
- - `R2_SECRET_ACCESS_KEY`: R2 secret access key from the Cloudflare R2 dashboard
133
- - `R2_BUCKET_NAME`: R2 bucket name from the Cloudflare R2 dashboard
141
+ - `PROJECT_SOURCE_DIRECTORY`: Source directory of your project by default it is `src`.
142
+ - `CROWDIN_BASE_PATH`: Base path of the translations in the Crowdin project by default it is `.`.
143
+ - `CROWDIN_BASE_URL`: Base URL of the CDN where the translations are stored, default is `https://api.crowdin.com`.
144
+ - `CROWDIN_BRANCH_NAME`: Running on production, test or staging etc.
145
+ - `CROWDIN_PROJECT_ID`: Crowdin project ID which can be found in the crowdin project settings.
146
+ - `CROWDIN_PERSONAL_TOKEN`: Crowdin personal token which can be found in the crowdin account settings.
147
+ - `R2_ACCOUNT_ID`: R2 account ID from the Cloudflare R2 dashboard.
148
+ - `R2_ACCESS_KEY_ID`: R2 access key ID from the Cloudflare R2 dashboard.
149
+ - `R2_SECRET_ACCESS_KEY`: R2 secret access key from the Cloudflare R2 dashboard.
150
+ - `R2_BUCKET_NAME`: R2 bucket name from the Cloudflare R2 dashboard.
134
151
 
135
- Refer to the action file [here](https://github.com/deriv-com/translations/blob/main/.github/actions/extract_and_sync_translations/action.yml)
152
+ Refer to the action file [here](https://github.com/deriv-com/translations/blob/main/.github/actions/extract_and_sync_translations/action.yml).
136
153
 
137
154
  ### Example usage of the action in the workflow file:
138
155
 
156
+ Copy and paste the following workflow code in your repository in this path`.github/workflows/sync_translations.yml`.
157
+
139
158
  ```yaml
140
159
  name: Sync translations
141
160
 
@@ -143,18 +162,18 @@ on:
143
162
  push:
144
163
  branches:
145
164
  - 'main'
165
+ schedule:
166
+ - cron: '0 */12 * * *'
146
167
 
147
168
  jobs:
148
169
  sync_translations:
149
170
  runs-on: ubuntu-latest
150
171
  steps:
151
- - name: Checkout to main branch
152
- uses: actions/checkout@v3
153
-
154
172
  - name: Sync translations
155
173
  uses: deriv-com/translations/.github/actions/extract_and_sync_translations@main
156
174
  with:
157
- CROWDIN_BRANCH_NAME: ${{ secrets.CROWDIN_BRANCH_NAME }}
175
+ PROJECT_NAME: ${{ env.PROJECT_NAME }}
176
+ CROWDIN_BRANCH_NAME: ${{ env.CROWDIN_BRANCH_NAME }}
158
177
  CROWDIN_BASE_URL: ${{ env.CROWDIN_BASE_URL }}
159
178
  CROWDIN_BASE_PATH: ${{ env.CROWDIN_BASE_PATH }}
160
179
  CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  }
17
17
  },
18
18
  "private": false,
19
- "version": "1.2.0",
19
+ "version": "1.2.2",
20
20
  "scripts": {
21
21
  "dev": "vite",
22
22
  "build": "tsc && vite build && cp ./src/scripts/deriv-extract-translations.cjs ./dist/deriv-extract-translations.cjs",