Giter Club home page Giter Club logo

crowdin-api-client-php's Introduction

Crowdin PHP client

The Crowdin PHP client is a lightweight interface to the Crowdin API. It provides common services for making API requests.

Our API is a full-featured RESTful API that helps you to integrate localization into your development process. The endpoints that we use allow you to easily make calls to retrieve information and to execute actions needed.

Requirements

  • PHP >= 7.1

Installation

Install via Composer

composer require crowdin/crowdin-api-client

Quick Start

The API client must be instantiated and configured before calling any API method.

use CrowdinApiClient\Crowdin;

$crowdin = new Crowdin([
    'access_token' => '<access_token>',
    'organization' => '<organization_domain>', // optional
]);

<access_token> - Personal Access Token. You can generate Personal Access Token in your Crowdin Account Settings.

<organization_domain> - Organization domain name (for Crowdin Enterprise users only).

For more about Authorization see the documentation.

Running methods

  • Create

    $directory = $crowdin->directory->create(
        <project_id>,
        ['name'=> 'My Directory']
    );
  • Edit

    $directory->setTitle('My Title');
    
    $crowdin->directory->update($directory);
  • Delete

    $crowdin->directory->delete($directory->getProjectId(), $directory->getId());

Seeking Assistance

If you find any problems or would like to suggest a feature, please read the How can I contribute section in our contributing guidelines.

Contributing

If you would like to contribute, please read the Contributing Guidelines.

License

The Crowdin PHP client is licensed under the MIT License.
See the LICENSE file distributed with this work for additional
information regarding copyright ownership.

Except as contained in the LICENSE file, the name(s) of the above copyright
holders shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written authorization.

crowdin-api-client-php's People

Contributors

andrii-bodnar avatar elliotbruneel avatar faizan1191 avatar ivdimova avatar jmleroux avatar kirejko avatar kmartin62 avatar krm-shrftdnv avatar mala-karta avatar misantron avatar mlahargou avatar pdelre avatar rvxlab avatar sidenser avatar soulshockers avatar syastrebov avatar tchapuis avatar trukes avatar uintaam avatar yozhef avatar zrnik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

crowdin-api-client-php's Issues

API to assign users to projects

Hey,

I would highly need an API to handle the user management which means:

  • Add/Remove person to a project with provided role
  • List persons of a project

I haven't seen that in the documentation yet.
What is your opinion on that?

Thanks!

AbstractTestApi::mockRequest fails to assert body & header

The two AbstractTestApi::mockRequest implementations have a bug (likely typo) where it will never assert the called body & header as the assertion is testing the same values ($params['body'] vs $params['body']).

if (isset($params['body'])) {
$this->assertEquals($params['body'], $params['body']);
}
if (isset($params['header'])) {
$this->assertEquals($params['header'], $params['header']);
}

if (isset($params['body'])) {
$this->assertEquals($params['body'], $params['body']);
}
if (isset($params['header'])) {
$this->assertEquals($params['header'], $params['header']);
}

This is masking 41 failures:

$ docker run -v $(pwd):/app --rm php:8.1-cli bash -c "cd app && vendor/bin/phpunit"
PHPUnit 9.6.13 by Sebastian Bergmann and contributors.

Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

..F....F...F....F..F....F....F..F.....F...F..........F.F...F...  63 / 396 ( 15%)
F...F..F....F.........F..F................F......F..F.F...F.... 126 / 396 ( 31%)
..F.......FE.F......F.F.F....F..F......F......FF..F.....F...... 189 / 396 ( 47%)
....F...F.F............F....................................... 252 / 396 ( 63%)
............................................................... 315 / 396 ( 79%)
............................................................... 378 / 396 ( 95%)
..................                                              396 / 396 (100%)

Time: 00:00.798, Memory: 18.00 MB
#...
ERRORS!
Tests: 396, Assertions: 1819, Errors: 1, Failures: 41.

Updating source strings is broken on server-side

When updating SourceStrings we get a 500 Internal Server Error. We're using a simple request like this:

    public function updateString($sourceId, $value): void
    {
        $sourceString = $this->client->sourceString->get($this->projectId, $sourceId);
        if (!$sourceString || $sourceString->getText() == $value) {
            return;
        }

        $sourceString->setText($value);
        $newString = $this->client->sourceString->update($sourceString);
    }

Add more examples of API Client usage

Currently, we have very few simple examples in the Readme and it would be great to have more examples that would include more complex workflows:

  • adding a file to the Crowdin project (add storage, add file)
  • updating a file (add storage, update or restore file)
  • build project (start to build, check build status in a loop, download project translations)
  • upload/download TM
  • upload/download Glossary

It's better to create a separate file for these examples like here.

[Improvement] Public items getter for `CrowdinApiClient\ModelCollection`

Hello,

I am testing a paginated reader in akeneo/nelson as follow:

        $results = [];
        $offset = 0;
        do {
            $objectCollection = $this->crowdinClient->translationStatus->getBranchProgress(
                $projectId,
                $branchId,
                ['offset' => $offset, 'limit'=>50]
            );
            foreach ($objectCollection->getIterator() as $item) {
                $results[]=$item;
            }
            $offset += $objectCollection->getPagination()['limit'];
        } while (!$objectCollection->isEmpty());

        return $results;

And i found it clumsy having to use the foreach iterator to just populate the results.
Having a public getter like CrowdinApiClient\ModelCollection::toArray() would be usefull imho.

The resulting pagination would be like

        $results = [];
        $offset = 0;
        do {
            $objectCollection = $this->crowdinClient->translationStatus->getBranchProgress(
                $projectId,
                $branchId,
                ['offset' => $offset, 'limit'=>50]
            );
            $results += $objectCollection->toArray();
            $offset += $objectCollection->getPagination()['limit'];
        } while (!$objectCollection->isEmpty());

        return $results;

Note, this could also be a CrowdinApiClient\ModelCollection::__toArray() method to reflect this RFC (still under discussion) https://wiki.php.net/rfc/to-array

Fetching machine translations suddenly yields only an internal server error

When trying to fetch machine translations of some strings we get a 500 Internal Server Error. We're using a request like this:

$machineTranslation = $this->crowdin->machineTranslationEngine->translateViaMT(
    $mtId,
    [
        'sourceLanguageId' => 'de',
        'targetLanguageId' => 'hr',
        'strings' => [
            'Test Eins',
            'Test Zwei',
        ],
    ]
);

The machine translation engine used supports the language pair and this requests worked before.

Support for PHP 8.1

Firstly, thank you for this interface!

We are upgrading PHP from 8.0 to 8.1 and are getting the following error:

Error: During inheritance of IteratorAggregate: Uncaught Whoops\Exception\ErrorException: Return type of CrowdinApiClient\Collection::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Anyways, I'm more than happy to create a PR to add the suppression attribute if that would be helpful.

Class 'CrowdinApiClient\Http\Client\CrowdinHttpClientFactory' not found

Ive downloaded the repository and placed it in my project.

I can require it (path is correct), but I get an error. Any idea what’s wrong?

<?php 

require 'scripts/libs/src/CrowdinApiClient/Crowdin.php';

use CrowdinApiClient\Crowdin;
Class 'CrowdinApiClient\Http\Client\CrowdinHttpClientFactory' not found

[Improvement] Add a `next_page` information to ModelCollection pagination

Hello,

Another question, following #113 .

Still with this paginated reader, I found that I have to make a useless empty API call to have an empty collection and exit the loop:

        $results = [];
        $offset = 0;
        do {
            $objectCollection = $this->crowdinClient->translationStatus->getBranchProgress(
                $projectId,
                $branchId,
                ['offset' => $offset, 'limit'=>50]
            );
            foreach ($objectCollection->getIterator() as $item) {
                $results[]=$item;
            }
            $offset += $objectCollection->getPagination()['limit'];
        } while (!$objectCollection->isEmpty());

        return $results;

I think I could add something like this to avoid this useless call:

        $results = [];
        $offset = 0;
        do {
            // call API with a limit = 50
        } while (!$objectCollection->isEmpty() || !$objectCollection->count() <= 50);


        return $results;

but it is also very clumsy and easy to forget. We may add the logic to test collection->count() < $limit in the client and return the info in the model to facilitate user pagination.

Readme.md image does not load on coming back from another file.

Screenshot (3)
The Readme. md image does not load on coming back from another file.

Note - Issue only in Github 'Default Dark' theme.

First, go to the repository home page where you will see the readme contents below, now go to any file and come back again to see the readme file doesn't load this time. I tried something by removing specific images for a light theme but that doesn't work cause now it shows light theme images in dark theme settings.
I am working on it and will find out what's the issue.

Note - Checked the Github doc for adding theme-specific images and found that we are doing it correctly. (https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#specifying-the-theme-an-image-is-shown-to)

Glossaries API updates

We're happy to announce a significant update for Crowdin Glossaries that allows managing the terminology in a more advanced way.

There are a lot of new things and some changes in the Crowdin API.

New APIs:

Updates:

The translationOfTermId is deprecated and the conceptId added in:

Edit Term - new path options

All of these changes should be reflected in this API Client.

Reports API changes

Crowdin recently released a big update of the reports functionality. Now, when calculating the price for translation in Cost Estimation and Translation Cost reports, we have introduced a new feature that allows you to include the cost of proofreading if the source text matches the Translation Memory (TM) or Machine Translation (MT) results.

The reports API was updated as well. The legacy Cost Estimate (including Fuzzy mode) and Translation Cost reports were deprecated in favor of the new Cost-Estimation Post-Editing and Translation Costs Post-Editing reports. The legacy reports will be removed in future releases.

API reference:

The Report Settings Template API was also affected (refer to the API Docs for details).

Tasks Settings Templates API support

Distributions API changes

The Distribution creation API has been changed. Now you can create a distribution with the following parameters:

  • bundleIds - array of bundle ids

The following parameters have been deprecated:

  • format
  • exportPattern
  • labelIds

A Distribution response has also been changed. Now it contains the bundleIds field. The format, exportPattern, and labelIds fields are deprecated.

In addition, the fileIds request parameter is now optional.

All the changes are described in the API documentation.

File ImportOptions improvement

We've added new possible import options for files:

  • Add File: new ImportOptions possible value - Docx File Import Options (including the response)

  • Update or Restore File: new ImportOptions possible value - Docx File Import Options (including the response)

  • Edit File: new /importOptions/* path parameters

So these changes should be reflected in this API Client.

Update API Docs links in the annotations

The crowdin.com and Crowdin Enterprise API docs were moved to the developer.crowdin.com domain instead of support.crowdin.com, so the URLs in the method annotations should be updated.

For crowdin.com:

https://support.crowdin.com/api/v2/* -> https://developer.crowdin.com/api/v2/*

For Crowdin Enterprise:

https://support.crowdin.com/enterprise/api/* -> https://developer.crowdin.com/enterprise/api/v2/*

\CrowdinApiClient\Api\TranslationApi::uploadTranslations missing content-type header

The \CrowdinApiClient\Api\TranslationApi::uploadTranslations function is missing the content-type "application/json" header.
This results in a 415 unsupported media type response.
Steps to reproduce:

  1. Create a storage e.g:
    1.1 $storage = $this->crowdin->storage->create(new \SplFileObject($file));
  2. Try to upload the storage as a translation file e.g:
$this->crowdin->translation->uploadTranslations($crowdinProjectId, $languageId, [
    'storageId' => $storage->getId(),
    'fileId' => $fileId,
]); 

SourceString fails on pluralized string

   TypeError 

  Return value of CrowdinApiClient\Model\SourceString::getText() must be of the type string, array returned

  at vendor/crowdin/crowdin-api-client/src/CrowdinApiClient/Model/SourceString.php:175
    171▕      * @return string
    172▕      */
    173▕     public function getText(): string
    174▕     {
  ➜ 175▕         return $this->text;
    176▕     }
    177▕ 
    178▕     /**
    179▕      * @param string $text

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.