Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
sargreal committed Mar 14, 2023
2 parents a4b0a7d + b19b726 commit d5039e8
Show file tree
Hide file tree
Showing 24 changed files with 2,298 additions and 1,644 deletions.
52 changes: 52 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
name: Bug report
about: Create a report to help us improve
title: "[BUG]: "
labels: investigate
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**System (please complete the following information):**
- OS: [e.g. Linux]
- Browser [e.g. firefox, safari, chrome]
- Versions:
- strapi: [e.g. 4.6.0]
- strapi-plugin-translate: [e.g. 1.1.0]
- provider: [e.g. [email protected]]
- Other Strapi plugins:
- [e.g. [email protected]]

**Plugin config**
Please add your plugin config here, e.g.
```js
module.exports = {
translate: {
enabled: true,
config: {
provider: '[e.g. deepl]',
providerOptions: { },
translateRelations: true,
},
},
}
```

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: "[FEATURE]: "
labels: enhancement
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
4 changes: 0 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@ version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
target-branch: "next"
schedule:
interval: "weekly"
- package-ecosystem: "npm"
directory: "/plugin/"
target-branch: "next"
schedule:
interval: "weekly"
- package-ecosystem: "npm"
directory: "/providers/deepl/"
target-branch: "next"
schedule:
interval: "weekly"
- package-ecosystem: "npm"
directory: "/playground/"
target-branch: "next"
schedule:
interval: "weekly"
5 changes: 1 addition & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: Pull Request
on:
pull_request:
branches-ignore:
- main
on: pull_request
jobs:
eslint:
runs-on: ubuntu-latest
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"workspaces": [
"plugin",
"providers/deepl",
"providers/libretranslate",
"playground"
],
"scripts": {
Expand All @@ -14,23 +15,23 @@
"release": "multi-semantic-release --ignore-private-packages"
},
"devDependencies": {
"@babel/eslint-parser": "^7.17.0",
"@babel/eslint-parser": "^7.19.1",
"@babel/preset-react": "^7.18.6",
"@commitlint/cli": "^17.4.4",
"@commitlint/config-conventional": "^17.4.2",
"@semantic-release/git": "^10.0.1",
"@feki.de/semantic-release-yarn": "^1.0.1",
"cz-conventional-changelog": "3.3.0",
"eslint": "^8.33.0",
"eslint-config-prettier": "^8.5.0",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^8.0.1",
"jest": "^29.4.1",
"lint-staged": "^13.1.0",
"lint-staged": "^13.2.0",
"multi-semantic-release": "^3.0.1",
"semantic-release": "^19.0.5"
},
Expand Down
1 change: 1 addition & 0 deletions playground/config/plugins.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = ({ env }) => ({
// ...
translate: {
resolve: "../plugin",
enabled: true,
config: {
provider: 'deepl',
Expand Down
12 changes: 5 additions & 7 deletions playground/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"dependencies": {
"@strapi/plugin-graphql": "^4.0.0",
"@strapi/plugin-graphql": "^4.7.1",
"lodash.set": "^4.3.2",
"mime-types": "^2.1.27",
"@strapi/strapi": "4.6.0",
"@strapi/plugin-users-permissions": "4.6.0",
"@strapi/plugin-i18n": "4.6.0",
"better-sqlite3": "8.1.0",
"strapi-plugin-translate": "1.0.0-next.2",
"strapi-provider-translate-deepl": "1.0.0-next.2"
"@strapi/strapi": "4.7.1",
"@strapi/plugin-i18n": "4.7.1",
"@strapi/plugin-users-permissions": "4.7.1",
"better-sqlite3": "8.2.0"
},
"name": "playground",
"private": true,
Expand Down
17 changes: 10 additions & 7 deletions plugin/admin/src/components/CMEditViewTranslateLocale/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ import {
useNotification,
useQueryParams,
CheckPermissions,
request,
} from '@strapi/helper-plugin'
import { generateOptions } from '@strapi/plugin-i18n/admin/src/components/CMEditViewInjectedComponents/CMEditViewCopyLocale/utils'
import useContentTypePermissions from '@strapi/plugin-i18n/admin/src/hooks/useContentTypePermissions'
import selectI18NLocales from '@strapi/plugin-i18n/admin/src/selectors/selectI18nLocales'
import { axiosInstance } from '@strapi/plugin-i18n/admin/src/utils'
import _ from 'lodash'
import { getTrad } from '../../utils'
import permissions from '../../permissions'
Expand Down Expand Up @@ -153,11 +153,14 @@ const Content = ({
const { locale: sourceLocale } = localizations.find(
({ id }) => id == value
)
const { data: translatedData } = await axiosInstance.post(translateURL, {
id: value,
sourceLocale,
targetLocale: currentLocale,
contentTypeUid: slug,
const translatedData = await request(translateURL, {
method: 'POST',
body: {
id: value,
sourceLocale,
targetLocale: currentLocale,
contentTypeUid: slug,
},
})

const parsedData = parseRelations(translatedData, allLayoutData)
Expand Down Expand Up @@ -247,7 +250,7 @@ const Content = ({
{isOpen && (
<Dialog onClose={handleToggle} title="Confirmation" isOpen={isOpen}>
<DialogBody icon={<ExclamationMarkCircle />}>
<Stack size={2}>
<Stack spacing={2}>
<Flex justifyContent="center">
<CenteredTypography id="confirm-description">
{formatMessage({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ export default function parseRelations(data, allLayoutData, component = null) {
value.map((r) => parseRelation(r, metadata, relationEditLayout))
)
} else {
_.set(result, attribute, [
parseRelation(value, metadata, relationEditLayout),
])
_.set(
result,
attribute,
value ? [parseRelation(value, metadata, relationEditLayout)] : []
)
}
} else if (attributeData.type === 'component') {
_.set(
Expand Down
3 changes: 2 additions & 1 deletion plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "strapi-plugin-translate",
"version": "1.1.0-next.1",
"version": "1.1.1",
"description": "Strapi plugin for managing and automating translation of content",
"strapi": {
"name": "translate",
Expand All @@ -12,6 +12,7 @@
"lint": "eslint ."
},
"dependencies": {
"@strapi/helper-plugin": "^4.1.4",
"axios": "^1.2.2",
"bottleneck": "^2.19.5",
"jsdom": "^21.0.0",
Expand Down
4 changes: 2 additions & 2 deletions providers/deepl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "strapi-provider-translate-deepl",
"version": "1.1.0-next.4",
"version": "1.1.1",
"description": "DeepL provider for translate plugin in Strapi 4",
"keywords": [
"strapi",
Expand Down Expand Up @@ -55,6 +55,6 @@
},
"peerDependencies": {
"lodash": "*",
"strapi-plugin-translate": "1.1.0-next.1"
"strapi-plugin-translate": "1.1.1"
}
}
9 changes: 9 additions & 0 deletions providers/libretranslate/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2022 Feki.de e.V.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
51 changes: 51 additions & 0 deletions providers/libretranslate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# LibreTranslate provider for Strapi Translate Plugin

Configure the provider through the providerOptions:

```js
module.exports = {
// ...
translate: {
enabled: true,
config: {
// Choose one of the available providers
provider: 'libretranslate',
// Pass credentials and other options to the provider
providerOptions: {
// your API key - required and wil cause errors if not provided
apiKey: 'key',
// api url - required
apiUrl: 'https://your.libretranslate.instance',
// maximum number of requests per minute - optional, default is `undefined` => no limit
apiMaxRPM: 60,
// maximum number of chars per request - optional, default is `undefined` => no limit
apiMaxChars: 1234,
// maximum number of texts per request
apiMaxTexts: 55,
// manually overwrite the Strapi Locale to LibreTranslate Locale mapping.
// default is the string before the `-` character for every locale
localeMap:{
'en-US' : 'de',
}
},
// other options ...
},
},
// ...
}
```

or use the default environment variables:

- `LT_API_KEY` - default `undefined`
- `LT_API_URL` - default `undefined`
- `LT_API_MAX_RPM` - default `undefined`
- `LT_API_MAX_CHARS` - default `undefined`
- `LT_API_MAX_TEXTS` - default `undefined`

Note that environment variables take precedence over values `providerOptions`. To force no limit on requests per second or maximum characters, set them to -1

## Limitations:

- Only the [languages supported by argos](https://github.com/argosopentech/argos-translate#supported-languages), the actual translation library behind LibreTranslate, can be translated.
- LibreTranslate servers can impose additional restrictions, such as limits to request frequency or size. You can configure those via the pluginOptions, by default there are no limitations, because [LibreTranslate has no limitations by default](https://github.com/LibreTranslate/LibreTranslate#arguments)
67 changes: 67 additions & 0 deletions providers/libretranslate/__mocks__/initStrapi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict'

module.exports = ({ plugins = {} }) => {
let mock = {
plugin(name) {
return this.plugins[name]
},
getRef() {
return this
},
plugins: {
...plugins,
translate: {
service(name) {
return this.services[name]({ strapi: mock.getRef() })
},
controller(name) {
return this.controllers[name]({ strapi: mock.getRef() })
},
services: {
chunks: require('strapi-plugin-translate/server/services/chunks'),
format: require('strapi-plugin-translate/server/services/format'),
},
},
'content-type-builder': {
service(name) {
return this.services[name]
},
services: {
components: {
// To make it easier here, the componentInfo is actually already in the correct format
formatComponent(componentInfo) {
return componentInfo
},
},
'content-types': {
formatContentType(contentTypeInfo) {
return contentTypeInfo
},
},
},
},
},
service(uid) {
const [handler, collection] = uid.split('::')
if (handler === 'plugin') {
const [plugin, service] = collection.split('.')
return this.plugins[plugin].services[service]({ strapi: mock.getRef() })
}
return {
findOne: (id, params) => this.entityService.findOne(uid, id, params),
find: (params) => this.entityService.findMany(uid, params),
create: (params) => this.entityService.create(uid, params),
update: (id, params) => this.entityService.update(uid, id, params),
delete: (id, params) => this.entityService.delete(uid, id, params),
}
},
log: {
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
},
}

return mock
}
Loading

0 comments on commit d5039e8

Please sign in to comment.