Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
7d82804
test(playground): upgrade playground to strapi@v5
sargreal Aug 22, 2024
76f3455
feat(plugin): migrate plugin to strapi v5
sargreal Aug 22, 2024
dfc0723
fix(admin): migrate direct translation to a header action
sargreal Sep 21, 2024
c8df746
feat: create translateEntity service
sargreal Sep 21, 2024
ea9ebab
test(plugin): update tests for typescript and strapi v5
sargreal Oct 10, 2024
e08e296
chore: fix package.json scripts
sargreal Oct 10, 2024
1200472
fix(admin): select default locale by default in translation
sargreal Oct 12, 2024
ad7d253
refactor: remove console logs
sargreal Oct 12, 2024
f1f9c18
fix: update config.get usage
sargreal Oct 12, 2024
3b8e1e8
fix: populate rule
sargreal Oct 12, 2024
0dc7771
chore(playground): fix reset script
sargreal Oct 12, 2024
6708c72
test: first changes to e2e tests
sargreal Oct 13, 2024
86215b3
fix: updated entry subscription
sargreal Oct 15, 2024
25e1754
fix(batch-update): tables and hooks
sargreal Nov 19, 2024
31789d5
fix: route for deleting updated entries
sargreal Nov 19, 2024
8996eef
fix(translate): cleaning data
sargreal Nov 19, 2024
1b4d1b4
refactor: serverside errorhandling
sargreal Nov 19, 2024
855fd82
fix(translateEntity): creating and updating of entities
sargreal Nov 19, 2024
8bd01d0
fix(batchUpdate): correctly handle updating in batch
sargreal Nov 19, 2024
d8829c6
build(deps): update strapi
sargreal Nov 19, 2024
4ea71b2
ci: enable corepack
sargreal Nov 20, 2024
f3fe0dc
ci(e2e): test on latest strapi versions
sargreal Nov 20, 2024
83aa719
ci(e2e): fix yarn pack options
sargreal Nov 20, 2024
6ceb2f6
ci(lint): use node 20 for eslint
sargreal Nov 20, 2024
c836253
ci(e2e): update package.json template
sargreal Nov 20, 2024
7b5565f
ci(lint): add plugin verify job
sargreal Nov 20, 2024
80c5619
ci(e2e): build plugin
sargreal Nov 20, 2024
8e011f7
ci: update actions versions
sargreal Nov 20, 2024
331f20b
ci(unittests): setup test reports with
sargreal Nov 20, 2024
aedefbf
test(mocks): fix plugin config retrieval
sargreal Nov 20, 2024
2513969
test(utils): update test files
sargreal Nov 20, 2024
63f9d28
refactor: remove console logs
sargreal Nov 20, 2024
c4eaf83
test: remove comment
sargreal Nov 20, 2024
bb2b185
fix: export types from shared
sargreal Nov 22, 2024
a921e19
feat(provider): migrate providers to typescript
sargreal Nov 28, 2024
ea2c36b
ci(lint): verify providers as well
sargreal Dec 12, 2024
0a0b392
build(plugin): fix export targets
sargreal Dec 12, 2024
e0547d2
ci(unittest): build plugin before tests
sargreal Dec 12, 2024
c111aa1
ci(release): build plugin and providers
sargreal Dec 12, 2024
11b7558
chore: remove unused imports
sargreal Dec 17, 2024
498f14a
fix(admin): cannot use useStrapi outside of StrapiApp
sargreal Jan 27, 2025
9ad25cb
test(batch-translate): migrate tests to typescript
sargreal Jan 29, 2025
1ab9d1d
test(untranslated-service): migrate tests to typescript
sargreal Jan 29, 2025
3065842
test(dummy-provider): migrate tests to typescript
sargreal Jan 29, 2025
5303220
fix(populate-all): break early if attributeSchema is empty
sargreal Jan 29, 2025
d2ed1e7
test(mock): throw error if content type does not exist
sargreal Jan 29, 2025
519370d
fix(utils): incorrect populate-all rule for dynamiczone and components
sargreal Jan 30, 2025
1d4522d
chore: remove duplicated code for entity translation
sargreal Jan 30, 2025
d295583
fix(admin): show alert on translation error again
sargreal Jan 30, 2025
ee34052
fix: batch translation stopping directly after setup
sargreal Jan 30, 2025
d369425
test(e2e): update tests to be more stable
sargreal Jan 30, 2025
575a8bf
test(plugin): update populate and controller tests
sargreal Jan 30, 2025
693f9ff
test(e2e): increase default timeout
sargreal Jan 30, 2025
1ee7b70
chore(deps): cleanup dependencies
sargreal Feb 2, 2025
5ac5895
chore(prettier): format all files
sargreal Feb 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
ecmaVersion: 2020,
requireConfigFile: false,
},
ignorePatterns: ['**/build', '**/dist', '**/node_modules'],
overrides: [
{
files: ['plugin/server/**/*.js', 'providers/**/lib/**/*.js'],
Expand Down Expand Up @@ -56,7 +57,12 @@ module.exports = {
{
files: ['plugin/admin/src/**/*.js', 'playground/src/admin/**/*.js'],
parser: '@babel/eslint-parser',
extends: ['eslint:recommended', 'plugin:react/recommended', 'prettier', 'plugin:jsx-a11y/recommended'],
extends: [
'eslint:recommended',
'plugin:react/recommended',
'prettier',
'plugin:jsx-a11y/recommended',
],
plugins: ['react', 'react-hooks', 'import'],
env: {
browser: true,
Expand Down
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
version: 2
updates:
- package-ecosystem: 'npm'
directories:
directories:
- '/'
- '/plugin/'
- '/providers/*'
Expand All @@ -16,4 +16,4 @@ updates:
groups:
strapi:
patterns:
- "@strapi/*"
- '@strapi/*'
14 changes: 10 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,24 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: yarn
run: npm ci
- name: Build strapi-plugin-translate
run: npm run build --workspace strapi-plugin-translate
- name: Build strapi-provider-translate-deepl
run: npm run build --workspace strapi-provider-translate-deepl
- name: Build strapi-provider-translate-libretranslate
run: npm run build --workspace strapi-provider-translate-libretranslate
- name: Release
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: yarn release
run: npm run release
2 changes: 1 addition & 1 deletion .github/workflows/diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ jobs:
diff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Run diff script
run: sh ./scripts/diff.sh
25 changes: 15 additions & 10 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,38 @@ jobs:
strategy:
matrix:
node: [18, 20]
strapi: [4.19, 4.24, 4.25]
strapi: [5.6, 5.7, 5.8]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: 'yarn'
cache: 'npm'
- name: Install workspace dependencies
run: yarn
run: npm ci
- name: Build strapi-plugin-translate
run: npm run build --workspace strapi-plugin-translate
- name: Pack strapi-plugin-translate
run: yarn workspace strapi-plugin-translate pack -f strapi-plugin-translate.tgz
run: |
PACKAGE_NAME=$(npm pack --workspace strapi-plugin-translate | tail -n 1);
echo "PACKAGE_NAME=${PACKAGE_NAME}" >> "$GITHUB_ENV"
- name: Copy playground to e2e folder
run: cp -r playground e2e
- name: Configure strapi version for e2e test
run: VERSION=${{ matrix.strapi }} envsubst < e2e/templates/template.package.json > e2e/package.json
- name: Install e2e dependencies
run: yarn
run: npm install
working-directory: e2e
- name: Add local strapi-plugin-translate
run: yarn add ../plugin/strapi-plugin-translate.tgz
run: npm install ../${PACKAGE_NAME}
working-directory: e2e
- name: Build strapi for e2e tests
run: yarn build
run: npm run build
working-directory: e2e
- name: Run e2e tests
run: yarn e2e
run: npm run e2e
working-directory: e2e
- name: Upload cypress results on failure
uses: actions/upload-artifact@v4
Expand Down
37 changes: 33 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,45 @@ jobs:
eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install modules
run: yarn
run: npm ci
- name: Run ESLint
run: yarn lint
run: npm run lint

verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install modules
run: npm ci
- name: Build strapi-plugin-translate
run: npm run build --workspace strapi-plugin-translate
- name: Build strapi-provider-translate-deepl
run: npm run build --workspace strapi-provider-translate-deepl
- name: Build strapi-provider-translate-libretranslate
run: npm run build --workspace strapi-provider-translate-libretranslate
- name: Verify plugin with strapi-plugin
run: npm run verify --workspace strapi-plugin-translate
- name: Verify strapi-provider-translate-deepl
run: npm run verify --workspace strapi-provider-translate-deepl
- name: Verify strapi-provider-translate-libretranslate
run: npm run verify --workspace strapi-provider-translate-libretranslate

commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v5
22 changes: 17 additions & 5 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,29 @@ jobs:
version: [18, 20]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.version }}
cache: 'yarn'
- run: yarn
- run: yarn test
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build strapi-plugin-translate
run: npm run build --workspace strapi-plugin-translate
- name: run tests
run: npm run test
- uses: codecov/codecov-action@v5
with:
files: ./plugin/coverage/clover.xml,./providers/deepl/coverage/clover.xml,./providers/libretranslate/coverage/clover.xml
flags: unittests
name: codecov-umbrella
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: test report
uses: dorny/test-reporter@v1
if: success() || failure() # run this step even if previous step failed
with:
name: unittest report (node=${{ matrix.version }}) # Name of the check run which will be created
path: reports/jest-*.xml # Path to test results
reporter: jest-junit # Format of test results
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ dist
.vscode

build/
reports/


**/cypress/videos
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint-staged
npm run lint-staged
11 changes: 11 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
reports
dist
coverage
.env
exports
*.cache
build
.strapi-updater.json
playground/types
.strapi
playground/public
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,20 @@ Enhancement suggestions are tracked as [GitHub issues](https://github.com/Fekide

#### Required tooling <!-- omit in toc -->

- node 14-18
- yarn
- node 18-20
- npm

#### Setup <!-- omit in toc -->

```bash
yarn install
npm install
```

#### Before commiting <!-- omit in toc -->

```bash
yarn test
yarn lint
npm run test
npm run lint
```

<!-- TODO
Expand All @@ -150,7 +150,7 @@ Updating, improving and correcting the documentation

We use [conventional-commits](https://www.conventionalcommits.org/en/v1.0.0/).

Please follow these guidelines or execute `yarn commit` to trigger `commitizen`
Please follow these guidelines or execute `npm run commit` to trigger `commitizen`

## Join The Project Team

Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ module.exports = {
],
// If relations should be translated (default true)
translateRelations: true,
// ignore updates for certain content types (default [], i.e. no content types are ignored)
ignoreUpdatedContentTypes: ['api::category.category'],
// wether to regenerate uids when batch updating (default false)
regenerateUids: true,
},
},
// ...
Expand Down Expand Up @@ -178,6 +182,14 @@ Additional remarks:
- UIDs are automatically translated in batch translation mode, since otherwise the entities could not be created/published
- If an error occurs, this will be shown in the logs or the message can be accessed by hovering over the `Job failed` badge

### Retranslating updated entities

If a localized entity is updated, an entry is added to the batch update section of the admin page. This allows easy retranslation of updated entities.
By default, uids will be ignored. You can opt to regenerate them by setting the `translate.config.regenerateUids` key of the plugin options to `true`.
The `translate.config.ignoreUpdatedContentTypes` key of the plugin options can be used to define an array of content types for which such updates should not be recorded.

Note that updates are only considered if they trigger the `afterUpdate` lifecycle hook provided by strapi.

### Schema for translating relations

_The related objects are not translated directly, only the relation itself is translated_
Expand Down
51 changes: 51 additions & 0 deletions changes.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
* Unmerged path plugin/admin/src/components/CMEditViewTranslateLocale/index.tsx
* Unmerged path plugin/admin/src/components/CMEditViewTranslateLocale/utils/parse-relations.ts
diff --git a/plugin/admin/src/components/CMHeaderActions.tsx b/plugin/admin/src/components/CMHeaderActions.tsx
index 6305b5d..c892c8b 100644
--- a/plugin/admin/src/components/CMHeaderActions.tsx
+++ b/plugin/admin/src/components/CMHeaderActions.tsx
@@ -27,6 +27,7 @@ import { Modules, UID } from '@strapi/strapi'
import parseRelations from '../utils/parse-relations'
import { unset } from 'lodash'
import useUsage from '../Hooks/useUsage'
+import flattenEntity from 'src/utils/flattenEntity'

interface I18nBaseQuery {
plugins?: {
@@ -50,7 +51,7 @@ export const TranslateFromAnotherLocaleAction: HeaderActionComponent = ({
const [localeSelected, setLocaleSelected] = React.useState<string | null>(
null
)
- const setValues = useForm('TranslateFromAnotherLocale', (state) => state.setValues)
+ const onChange = useForm('TranslateFromAnotherLocale', (state) => state.onChange)
const [translateEntity] = useTranslateEntityMutation()
const { schema, components } = useDocument({
model,
@@ -135,17 +136,21 @@ export const TranslateFromAnotherLocaleAction: HeaderActionComponent = ({
parsedData[key] = document[key]
})

- for (const key in parsedData) {
- const attribute = schema.attributes[key]
+ const flattenedData = flattenEntity(parsedData, {contentType: schema, components, editLayout})

- if (attribute) {
- if (attribute.type === 'json') {
- parsedData[key] = JSON.stringify(parsedData[key], undefined, 2)
+ for (const key in flattenedData) {
+ if (Object.hasOwnProperty.call(flattenedData, key)) {
+ let { value, type } = flattenedData[key]
+
+ if (type) {
+ if (type === 'json') {
+ value = JSON.stringify(value)
+ }
+ onChange("",{ target: { name: key, value, type } })
}
}
}

- setValues(parsedData)
setLoading(false)
}

26 changes: 26 additions & 0 deletions jest-preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict'

module.exports = {
// setupFilesAfterEnv: [__dirname + '/tests/setup/unit.setup.js'],
modulePathIgnorePatterns: ['.cache', 'dist'],
testPathIgnorePatterns: [
'.testdata.{js,ts}',
'.test.utils.{js,ts}',
'.d.ts',
'__tests__/resources',
'tests/resources',
],
// prettierPath: require.resolve('prettier-2'),
testMatch: ['**/__tests__/**/*.{js,ts,jsx,tsx}'],
transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest'],
},
// Use `jest-watch-typeahead` version 0.6.5. Newest version 1.0.0 does not support jest@26
// Reference: https://github.com/jest-community/jest-watch-typeahead/releases/tag/v1.0.0
// watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
projects: [
'<rootDir>/plugin/jest.config.js',
'<rootDir>/providers/*/jest.config.js',
// '<rootDir>/.github/actions/*/jest.config.js',
],
}
Loading
Loading