Skip to content

[Translation][FrameworkBundle] Adding Translation Providers #37462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

welcoMattic
Copy link
Member

@welcoMattic welcoMattic commented Jun 30, 2020

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #36543
License MIT
Doc PR todo

This PR refers to the early opened RFC #36543 about adding third party translation SaaS into Symfony.
I worked in collaboration with @odolbeau on this first draft.

We have implemented only Loco Provider for now, to validate the main workflow of the feature.
We are not very sure about some naming convention, such as Remote StorageProvider, it might be renamed in Transport, to correspond to the naming of third party services in Mailer and Notifier Components.

This PR brings 2 new commands in FrameworkBundle: translation:push and translation:pull
It adds also new configuration entry:

framework:
    default_locale: fr
    translator:
        default_path: '%kernel.project_dir%/translations'
        enabled_locales: '%locales%'
        fallbacks:
            - en
            - it
        providers:
            loco:
                dsn: '%env(LOCO_DSN)%'
                domains: ['messages']
                locales: '%locales%'

To do

  • Implement Remote StoragesProvider into Translation component
  • Plug it into FrameworkBundle
  • Implement pull and push commands
  • Implement Loco adapter
  • Implement Transifex Provider (:warning: API key could contains special characters like /, +, :, @, #, %, etc..., we must mention it in documentation and warn users to encode those special characters before paste them in .env)
  • Implement POEditor Provider (:warning: there is a trick to do in POEditor Dashboard in order to make XLF export works, it will have to be documented explicitly in the symfony/symfony-docs PR)
  • Implement Crowdin Provider (:pause_button: stand by, the API is more complex to use than other Translation Management Systems)
  • Tests
  • Documentation
  • Update CHANGELOG.md files in FrameworkBundle and Translation Component

Transifex Provider

To do:

  • Ensure that the creation of a Resource per translation key is the right way to do, if not re-work this part
  • Implement API call for Translation creation
  • Implement API call for Resource (means translation key) deletion

Crowdin Provider

To do:

  • Implement Add Storage and Add File API calls in order to create translations keys in Crowdin from the default locale local file
  • Implement Add Translation API call to send translation messages
  • Implement Update File API call in order to add or delete a translation key from a File

@welcoMattic welcoMattic changed the title Feature/remote storages [Translation][FrameworkBundle] Adding translation remote storages Jun 30, 2020
@nicolas-grekas nicolas-grekas added this to the next milestone Jun 30, 2020
@YaFou
Copy link
Contributor

YaFou commented Jul 1, 2020

I'm really interested in this new feature! Thank you, it's promising! 👏 I also have another adapter that can be implemented: Crowdin.

@welcoMattic welcoMattic force-pushed the feature/remote-storages branch from 326c05e to de0138f Compare July 1, 2020 08:52
@welcoMattic welcoMattic force-pushed the feature/remote-storages branch 2 times, most recently from 5beef58 to b9f5792 Compare July 1, 2020 13:05
@welcoMattic welcoMattic marked this pull request as ready for review August 7, 2020 10:14
@welcoMattic welcoMattic force-pushed the feature/remote-storages branch 3 times, most recently from 43a9251 to 9a230fd Compare August 7, 2020 14:12
@YaFou
Copy link
Contributor

YaFou commented Aug 8, 2020

@welcoMattic for the Transifex bridge, have you try to use %2F to escape / for the token?

@welcoMattic welcoMattic force-pushed the feature/remote-storages branch from aa50e05 to db0a76d Compare August 10, 2020 12:22
@welcoMattic
Copy link
Member Author

Before continuing the work on this PR, I ask myself several questions:

  • Should we rename RemoteStorage to Transport? (like in Notifier, Mailer, ...)
  • How many built-in SaaS client should we support for this first PR (should we release other "Transports" later in separate packages as it's done in Notifier?)
  • Should we simplify the AbstractFactory part? (after all I think is very complex for no obvious reason)

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just done a very very quick review to better understand the PR and its goals.


use Symfony\Component\Translation\TranslatorBag;

class RemoteDecorator implements RemoteInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it useful?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is in the read method, that we merge wanted domains (passed as arguments in commands) with default domains (defined in configuration)

@fabpot
Copy link
Member

fabpot commented Sep 7, 2020

I think we would need at least 2 (or 3) providers to exercise the API and be sure it's generic and powerful enough.
I like the feature and I'd love to add it to 5.2 if possible.

@welcoMattic
Copy link
Member Author

Thank you for the review. I'm ok to add 2 or 3 Providers (I will rename RemoteStorage for Provider).
I hope too include this feature in 5.2 release, I will do my best to work regularly on it, in order to be ready for 5.2.

@welcoMattic welcoMattic force-pushed the feature/remote-storages branch from 7d48c0c to 5afca3b Compare September 28, 2020 21:16
@welcoMattic
Copy link
Member Author

@andrii-bodnar Hi, sorry but I do not understand how Crowdin API works for uploading translations. You mentioned the Upload Translations endpoint, but in the documentation, there is no mention of content uploading. How do I upload existing translations and in which format?

@andrii-bodnar
Copy link
Contributor

Hi @welcoMattic,

let's imagine you have domain admin.en.xlf and French translations - admin.fr.xlf

File admin.en.xlf is being added to the Crowdin project.

Now, if you want to upload admin.fr.xlf translations to Crowdin, you need to create a Storage with this file and use Upload Translations method. This method accepts storageId (admin.fr.xlf) and fileId (admin.en.xlf file ID)

@welcoMattic
Copy link
Member Author

@andrii-bodnar thank you for the quick answer. Ok, it's not very easy to understand the concepts of Storage and File, moreover with an Upload operation between them. But ok, I will try to implement this workflow in Symfony. Thanks again.

@welcoMattic
Copy link
Member Author

@andrii-bodnar can we discuss by email or in Symfony Slack? I still have difficulties to send existing translations to Crowdin.

@andrii-bodnar
Copy link
Contributor

@welcoMattic, sure, I'll try to join Symfony Slack.

@stephane-lou
Copy link

This is a very welcome feature, thanks for the work guys !

@welcoMattic welcoMattic force-pushed the feature/remote-storages branch from 5afca3b to d88294e Compare September 30, 2020 09:03
@welcoMattic
Copy link
Member Author

Well, there's still a lot of work here before we get to a complete and stable functionality (especially for the Provider Crowdin), and then the functional tests are not written yet.

For Crowdin, we have been working the last few days with @andrii-bodnar in order to implement all needed API calls, and it remains the delete method to implement, but Crowdin API does not allow fine deletion for translations keys. It's planned on their side to introduce such an endpoint very soon.

For Transifex, I need to work again the Provider, and explore the API more deeply to find the right way to do things.

For all these reasons, I think we should target a merge for 5.3, it's more reasonable than speed up work and merge an unstable feature in 5.2.

@fabpot fabpot closed this Oct 7, 2020
@fabpot
Copy link
Member

fabpot commented Oct 7, 2020

We've just moved away from master as the main branch to use 5.x instead. Unfortunately, I cannot reopen the PR and change the target branch to 5.x. Can you open a new PR referencing this one to not loose the discussion? Thank you for your understanding and for your help.

@nicolas-grekas nicolas-grekas modified the milestones: 5.x, 5.2 Oct 14, 2020
fabpot added a commit that referenced this pull request Apr 21, 2021
This PR was merged into the 5.3-dev branch.

Discussion
----------

[Translation] Adding Translation Providers

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #36543
| License       | MIT
| Doc PR        | todo

> Follow up of #37462

This PR refers to the early opened RFC #36543 about adding third party translation SaaS into Symfony.
I worked in collaboration with `@odolbeau` on this first draft.

We have implemented only Loco Provider for now, to validate the main workflow of the feature.
~~We are not very sure about some naming convention, such as Remote Storage, it might be renamed in Transport, to correspond to the naming of third party services in Mailer and Notifier Components.~~ We use Provider name.

This PR brings 2 new commands in Translation component: `translation:push` and `translation:pull`
It adds also new configuration entry:

```yaml
framework:
    default_locale: fr
    translator:
        default_path: '%kernel.project_dir%/translations'
        enabled_locales: '%locales%'
        fallbacks:
            - en
            - it
        providers:
            loco:
                dsn: '%env(LOCO_DSN)%'
                domains: ['messages']
                locales: '%locales%'
```

## To do

- [x] Implement Provider into Translation component
- [x] Plug it into FrameworkBundle
- [x] Implement pull and push commands
- [x] Implement Loco adapter
- [x] Tests
- [ ] Documentation
- [x] Update CHANGELOG.md files in FrameworkBundle and Translation Component

Docs:

Adapt language settings in Lokalise to be sure that Symfony locales match with Lokalise languages

![language-setting-lokalise](https://user-images.githubusercontent.com/773875/102089496-997c5200-3e1c-11eb-8bff-bd2f9a5fe100.png)

Todo:

- [x] Implement POEditor Provider (:warning: there is a trick to do in POEditor Dashboard in order to make XLF export works, it will have to be documented explicitly in the symfony/symfony-docs PR)
- [x] Implement Lokalise Provider
- [x] Implement Crowdin Provider

These 3 providers are implemented separately. They are not fully tested yet, it is planned to make it done by the end of April 2021.

Commits
-------

6e55fa8 Added Translation Providers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC] [Translation] Remote Storages