Skip to content
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

Crowdin API v2, allow editing of any files as XLIFF #633

Closed

Conversation

berezins
Copy link
Contributor

@berezins berezins commented May 24, 2020

Added support (from customer's prospective):

  • Crowdin for enterprise
    • Works with Crowdin Enterprise accounts of any organization (on any domains)
  • Open/save/sync as Xliff any file which can be parsed for translations by Crowdin
  • While continue to work with PO natively as is

Improved

  • Path to locally stored Crowdin files contains <project name>/<lang code>/<branch><path to file in Crowdin project>
  • Files opened via Open from Crowdin can be saved/synced back to Crowdin on further open and edit as local file from file system (simplest from File menu's Recent list/history)

Migrated to new:

  • OAuth improved/updated that works with API v2
  • API v2

This PR is clean version of #629 with

  • Work with PO natively (as is without converting to/from Xliff) is back
  • Clean/arranged/grouped commits
  • Back to implicit flows with few improvements
    • state param passed to OAuth URL and checked when callback received
    • OAuth URL redirect via poedit.net replaced with direct to Crowdin OAuth URL but source tracking params added (to identify authentication via Poedit for statistics)

- OAuth URL redirect via poedit.net replaced with direct to Crowdin OAuth URL but source tracking params added (to identify authentication via Poedit for statistics)
- `state` param passed to OAuth URL and checked when callback URL with token received
- Works already one new API `/user` so it shows that authenticated and full name of the user at the end of authentication process (when Authorize button pressed on authorization page)
JWT parsing without third-party deps
As it seems create some problem on MacOS plust looks more simple/elegant
i.e. which are not authorized to get file list etc.
from temporary arbitrary URL returned by API
In dropdown list of "Open from Crowdin" dialog
i.e. `{` from new line unless omitted due of single-line statement
@berezins berezins force-pushed the crowdin-new-oauth-api-xliff-clean branch 2 times, most recently from 5cdd02c to 5d9204e Compare May 31, 2020 12:59
Without type casts in this commit.

- Tried on GCC 7 and 8 with -std=gnu++14 and 17
- Even with latest as of now nlohmann/json@c05bd90
- While no errors on Visual Studio and Xcode without those casts
@berezins berezins force-pushed the crowdin-new-oauth-api-xliff-clean branch from 3f21d4e to f7e6799 Compare June 13, 2020 13:51
In cpprest (casablanka) RESTful client
Now all files are supported
for setting remote (Crowdin side) file extension
- Fixed naming projName=>projIdentifier
- Improved error messages to be more clear, excplanatory and precise
@berezins berezins force-pushed the crowdin-new-oauth-api-xliff-clean branch from 3792a79 to 6df545e Compare June 18, 2020 13:18
berezins and others added 6 commits June 18, 2020 16:31
In `Catalog`

Also improved detection of files opened from Crowdin via `Open from Crowdin` dialog (added "CrowdinSync_" at the beginning of each such filename)
And stuff related to it in `XLIFF1Catalog` and `XLIFF2Catalog`
There needs to be / between the prefix and the relative URLs; to keep
the changes minimal, put it in the prefix.
gettext translations are normally uploaded as a POT file, not PO, while
translations themselves are PO. Handle this case correctly.
Caught by Visual C++'s warning about comparing bool to int.

Rephrased the condition to be more verbose, but more readable and less
error-prone.
src/catalog.cpp Outdated
@@ -602,8 +602,10 @@ void Catalog::SetFileName(const wxString& fn)

bool Catalog::IsFromCrowdin() const
{
if((m_crowdinFileId > 0 && m_crowdinProjectId) > 0
Copy link
Contributor Author

@berezins berezins Jun 22, 2020

Choose a reason for hiding this comment

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

Yep, that was definitely my "typo" during refactoring and I would never write above intentently :). And many apologies for this. That is why Visual Studio complained about it and it's pure luck it worked as expected (due Crowdin seems never assigns 0 to IDs) . It intended to be (m_crowdinFileId > 0 && m_crowdinProjectId > 0) definitely. Anyway thanks a lot for catching this up and fixing

Copy link
Owner

Choose a reason for hiding this comment

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

and I would never write above intentently :)

Of course. I'm simultaneously impressed that MSVC caught it and surprised than neither relatively modern GCC nor Clang did.

@berezins berezins force-pushed the crowdin-new-oauth-api-xliff-clean branch from e0aa0b7 to dced359 Compare June 22, 2020 13:31
@vslavik
Copy link
Owner

vslavik commented Jun 24, 2020

Thank you! I have now pushed most of the PR to the crowdin-v2 branch; please use that as the basis for any changes. Some missing bits are because I think I can come up with better solution:

  • no bSkipUpload
  • no AttachCloudSync changes

I also improved formatting, fixed broken uses of gettext's _(), restored link attribution code to minimize changes, made some more trivial tweaks. For reference, this is a diff from what I committed to this PR, except for trivial formatting changes. In other words, applying this patch to crowdin-v2 branch restores your PR as-is:
from-committed-to-pr-not-applied-bits.patch.gz

@vslavik
Copy link
Owner

vslavik commented Jun 24, 2020

I forgot to say: I also rebased on the new (macOS) networking implementation.

There's one known problem: syncing PO files fails.

  1. Click on Collaborate on a Translation with Others
  2. Choose "Poedit Testing Sandbox" project (I invited you), language e.g. Finnish, file default.po or any of the POT files, click OK.
  3. Immediately click the Sync toolbar button.
  4. Oops:

Screen Shot 2020-06-24 at 12 55 56

I thought my changes w.r.t PO vs POT handling caused it, but it's happening with PO too.

@vslavik
Copy link
Owner

vslavik commented Jun 27, 2020

There's one known problem: syncing PO files fails.

This is fixed in 54b86a9.

I am now seeing X-Crowdin-Project-ID and X-Crowdin-File-ID headers in PO files downloaded from Crowdin (both via API and manually). It seems that big part of 9a58ee3, namely CrowdinUpdateCatalogIDsFromHeaders, can be safely removed after all?

@berezins
Copy link
Contributor Author

berezins commented Jul 1, 2020 via email

@berezins
Copy link
Contributor Author

berezins commented Jul 1, 2020 via email

@vslavik vslavik closed this Jul 2, 2020
@vslavik vslavik mentioned this pull request Jul 2, 2020
@berezins
Copy link
Contributor Author

berezins commented Jul 2, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants