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
Closed
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
2166b61
OAuth to new API v2
berezins Feb 25, 2020
fa3751c
Download and open file in Xliff
berezins May 8, 2020
e400607
Local path matches path in Crowdin
berezins Mar 19, 2020
50d4381
Upload file as XLIFF
berezins Mar 22, 2020
b4a90b7
OAuth to any organization or personal account
berezins Mar 28, 2020
750e76a
Fixed empty first and last name in organization user
berezins Apr 8, 2020
753a5c8
Hide assets from list
berezins Apr 8, 2020
8cdd4fe
Fix compilation errors on newer wxWidgets versions
berezins Apr 10, 2020
2139b6e
Crashed when to Save file deleted on Crowdin side
berezins Apr 10, 2020
68d5e5e
Crashed on open cached Crowdin file if logged out
berezins Apr 10, 2020
b202e3c
Leading slash in API requests removed
berezins May 20, 2020
e7161c0
Move AttachCloudSync() to GUI code
berezins May 20, 2020
a3c5c45
Hide 'Forbidden' projects
berezins Apr 17, 2020
caf7330
Domain agnostic file download
berezins Apr 17, 2020
ca4d693
Full path in file list including branch
berezins Apr 23, 2020
1f910e6
Implicit conversion from json to json_data
berezins Apr 26, 2020
e824933
Logging using wxLogTrace()
berezins May 14, 2020
99261b0
`std` explicitly
berezins May 7, 2020
de53022
Predominant `if`/`for`/`while` formatting
berezins May 17, 2020
8f6f90b
GetUserInfo() fixed
berezins May 21, 2020
e06429f
Native PO file support back
berezins May 22, 2020
98ab380
Buildable on Windows (wxStandardPaths())
berezins May 24, 2020
b5771a5
Buildable on macOS (wxGetHomeDir() undefined)
berezins May 24, 2020
f190355
OAuth: TM (translation memory) scope is not needed
berezins May 25, 2020
9b7a084
Removed auto approval of uploaded translations
berezins May 25, 2020
efb1a7d
XLF extension is XLIFF as well
berezins May 25, 2020
89ce540
Removed `importDuplicates`
berezins May 25, 2020
2b4649e
Logging improved (FileDownload, FileUpload)
berezins May 31, 2020
9a58ee3
Save/Sync for PO downloaded from Crowdin in browser
berezins May 31, 2020
4ab1146
Handle OAuth token upgrade from v1 API (2.3 Poedit)
berezins May 31, 2020
a046666
State in OAuth URL is auto-generated
berezins Jun 8, 2020
6f2d699
Use to_string_t() to bring wide/narrow match
berezins Jun 8, 2020
4b647ef
Update JSON C++ lib to fix MSVC compilation (temp)
vslavik May 9, 2020
32a15a9
Removed VS2019 JSON workarounds
berezins Jun 9, 2020
37a00fb
Few fixes to string literals
berezins Jun 9, 2020
a6788fa
Comments on catching errors in crowdin_http_client
berezins Jun 9, 2020
11f638e
Catalog::SerFileName() no longer needed to be virtual
berezins Jun 9, 2020
d2ea08f
cloud_sync.h is not needed anymore in catalog.h
berezins Jun 9, 2020
731c266
Reverted back occasionally removed empty line
berezins Jun 9, 2020
508e4f9
Twice-upload on "Sync" (with Crowdin) pressed fixed
berezins Jun 13, 2020
f7e6799
GCC: "error: operands to ?: have different types"
berezins Jun 13, 2020
d81778a
GetUserInfo() refactored and commented
berezins Jun 13, 2020
a37bb61
Comment for removing "Accept: application/json"
berezins Jun 13, 2020
9bc52ba
`mb_str()` to `str::to_utf8()` changed
berezins Jun 15, 2020
cc58929
Token domain error handling and logging
berezins Jun 15, 2020
0fa48dd
Removed moving unsupported files to the end
berezins Jun 15, 2020
1d244ec
Explicit `CmpNoCase() != 0` and comment
berezins Jun 15, 2020
6df545e
Save/sync PO downloaded via Crowdin UI improved
berezins Jun 18, 2020
a711235
Put together most of Crowdin stuff to IsFromCrowdin()
berezins Jun 18, 2020
0dcedfa
m_language is back in `XLIFFCatalog`
berezins Jun 18, 2020
0bb4cb4
Compilation fix for bSkipUpload
vslavik Jun 19, 2020
e9db2d0
Fix bad API URL prefix
vslavik Jun 20, 2020
579d3d4
Really open PO files natively, even if uploaded as POT
vslavik Jun 20, 2020
dced359
Fix broken IsFromCrowdin() logic
vslavik Jun 20, 2020
0f76785
New OAuth app since old Client ID compromised
berezins Jun 22, 2020
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
2 changes: 1 addition & 1 deletion deps/json
Submodule json updated 1164 files
18 changes: 18 additions & 0 deletions src/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,24 @@ void Catalog::SetFileName(const wxString& fn)
m_fileName = f.GetFullPath();
}

bool Catalog::IsFromCrowdin() const
{
if (m_crowdinFileId > 0 && m_crowdinProjectId > 0)
return true;

if (m_header.HasHeader("X-Crowdin-Project") && m_header.HasHeader("X-Crowdin-File"))
return true;

auto name = wxFileName(m_fileName).GetName();
if(name.StartsWith("CrowdinSync_"))
{
name = name.AfterFirst('_');
name.ToLong(&m_crowdinProjectId);
name.AfterFirst('_').ToLong(&m_crowdinFileId);
}

return m_crowdinFileId > 0 && m_crowdinProjectId > 0;
}

namespace
{
Expand Down
9 changes: 6 additions & 3 deletions src/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,11 @@ class Catalog
virtual void SetLanguage(Language lang);

/// Is the PO file from Crowdin, i.e. sync-able?
bool IsFromCrowdin() const
{ return m_header.HasHeader("X-Crowdin-Project") && m_header.HasHeader("X-Crowdin-File"); }

bool IsFromCrowdin() const;
long GetCrowdinFileId() const { return m_crowdinFileId; }
long GetCrowdinProjectId() const { return m_crowdinProjectId; }
void SetCrowdinProjectAndFileId(int projId, int fileId) { m_crowdinProjectId = projId; m_crowdinFileId = fileId; }

/// Returns true if the catalog contains obsolete entries (~.*)
virtual bool HasDeletedItems() const = 0;

Expand Down Expand Up @@ -594,6 +596,7 @@ class Catalog
bool m_isOk;
Type m_fileType;
wxString m_fileName;
mutable long m_crowdinFileId = -1, m_crowdinProjectId = -1;
HeaderData m_header;
Language m_sourceLanguage;

Expand Down
2 changes: 1 addition & 1 deletion src/catalog_po.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ bool POCatalog::Load(const wxString& po_file, int flags)

Clear();
m_isOk = false;
m_fileName = po_file;
SetFileName(po_file);
m_header.BasePath = wxEmptyString;

wxString ext;
Expand Down
19 changes: 15 additions & 4 deletions src/catalog_xliff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "configuration.h"
#include "str_helpers.h"
#include "utility.h"
#include "crowdin_gui.h"

#include <wx/intl.h>
#include <wx/log.h>
Expand Down Expand Up @@ -378,7 +379,6 @@ bool XLIFFCatalog::CanLoadFile(const wxString& extension)
return extension == "xlf" || extension == "xliff";
}


std::shared_ptr<XLIFFCatalog> XLIFFCatalog::Open(const wxString& filename)
{
constexpr auto parse_flags = parse_full | parse_ws_pcdata | parse_fragment;
Expand All @@ -403,6 +403,7 @@ std::shared_ptr<XLIFFCatalog> XLIFFCatalog::Open(const wxString& filename)
else
throw XLIFFReadException(filename, wxString::Format(_("unsupported XLIFF version (%s)"), xliff_version));

cat->SetFileName(filename);
cat->Parse(xliff_root);

return cat;
Expand Down Expand Up @@ -595,14 +596,24 @@ class XLIFF10CatalogItem : public XLIFF12CatalogItem
}
};


void XLIFF1Catalog::Parse(pugi::xml_node root)
{
int id = 0;

for (auto file: root.children("file"))
{
m_sourceLanguage = Language::TryParse(file.attribute("source-language").value());
m_language = Language::TryParse(file.attribute("target-language").value());
// TODO: Only first `file` node atthributes are used for now
// what works well in case of either all next are same within
// same `xliff` or if the only single `file` node is there
// (what is always the only case for downloaded from Crowdin)
// But should be taken into account and improved for probable
// more wide varietty of cases in the future.
if(id == 0)
{
m_sourceLanguage = Language::TryParse(file.attribute("source-language").value());
m_language = Language::TryParse(file.attribute("target-language").value());
}

for (auto unit: file.select_nodes(".//trans-unit"))
{
auto node = unit.node();
Expand Down
29 changes: 29 additions & 0 deletions src/cloud_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "concurrency.h"

#include <wx/string.h>
#include <wx/stdpaths.h>
#include <wx/utils.h>

#if wxUSE_GUI
#include "customcontrols.h"
Expand Down Expand Up @@ -62,6 +64,7 @@ class CloudSyncDestination

/// Asynchronously uploads the file. Returned future throws on error.
virtual dispatch::future<void> Upload(CatalogPtr file) = 0;
virtual bool Auth(wxWindow* parent) = 0;
berezins marked this conversation as resolved.
Show resolved Hide resolved


/// Convenicence for creating a destination from a lambda.
Expand All @@ -83,6 +86,27 @@ class CloudSyncDestination

return std::make_shared<Dest>(name, std::move(func));
}

static const wxString& GetCacheDir()
{
static wxString localBaseDir;

if(localBaseDir.empty())
{

#if defined(__WXOSX__)
localBaseDir = wxGetHomeDir() + "/Library/Caches/net.poedit.Poedit";
#elif defined(__UNIX__)
if (!wxGetEnv("XDG_CACHE_HOME", &localBaseDir))
localBaseDir = wxGetHomeDir() + "/.cache";
localBaseDir += "/poedit";
#else
localBaseDir = wxStandardPaths::Get().GetUserDataDir() + wxFILE_SEP_PATH + "Cache";
#endif
}

return localBaseDir;
}
};


Expand Down Expand Up @@ -116,6 +140,11 @@ class CloudSyncProgressWindow : public wxDialog
/// Show the window while performing background sync action. Show error if
static void RunSync(wxWindow *parent, std::shared_ptr<CloudSyncDestination> dest, CatalogPtr file)
{
if(!dest->Auth(parent))
{
return;
}

wxWindowPtr<CloudSyncProgressWindow> progress(new CloudSyncProgressWindow(parent, dest));
#ifdef __WXOSX__
progress->ShowWindowModal();
Expand Down
Loading