### REST API Examples Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/README.md Examples of how to use the Crowdin PHP client for REST API operations. ```APIDOC ## Create Directory ### Description Creates a new directory in Crowdin. ### Method ```php $crowdin->directory->create($project_id, ['name'=> 'My Directory']) ``` ### Parameters - **project_id**: (integer) - The ID of the project. - **name**: (string) - The name of the directory to create. ### Request Example ```php $directory = $crowdin->directory->create( 12345, ['name'=> 'My Directory'] ); ``` ## Edit Directory ### Description Edits an existing directory in Crowdin. ### Method ```php $crowdin->directory->update($directory) ``` ### Parameters - **directory**: (object) - The directory object to update. ### Request Example ```php $directory->setTitle('My Title'); $crowdin->directory->update($directory); ``` ## Delete Directory ### Description Deletes a directory from Crowdin. ### Method ```php $crowdin->directory->delete($project_id, $directory_id) ``` ### Parameters - **project_id**: (integer) - The ID of the project. - **directory_id**: (integer) - The ID of the directory to delete. ### Request Example ```php $crowdin->directory->delete(12345, 67890); ``` ``` -------------------------------- ### GraphQL API Example Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/README.md Example of how to use the Crowdin PHP client for GraphQL API queries. ```APIDOC ## GraphQL Query ### Description Executes a GraphQL query against the Crowdin API. ### Method ```php $crowdin->graphql->query($query, $variables, $options) ``` ### Parameters - **query**: (string) - The GraphQL query string. - **variables**: (object|null) - Variables to be used in the query. - **options**: (array|null) - Additional options for the query, such as limit. ### Request Example ```php $query = 'query($limit: Int) { viewer { projects(first: $limit) { edges { node { name files(first: $limit) { totalCount edges { node { name type } } } } } } } }'; $response = $crowdin->graphql->query($query, null, ['limit' => 10]); ``` ``` -------------------------------- ### Create and Upload Glossary Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/EXAMPLES.md This example shows how to create a new glossary and then import content from a TBX file. It polls the import status until it's finished. The organization parameter is optional for Crowdin Enterprise. ```php use CrowdinApiClient\Crowdin; $crowdin = new Crowdin([ 'access_token' => '', 'organization' => '', // if you use Crowdin Enterprise ]); $glossary = $crowdin->glossary->create(['name' => 'Test Glossary', 'languageId' => 'en']); $storage = $crowdin->storage->create(new SplFileInfo('')); $glossaryImport = $crowdin->glossary->import($glossary->getId(), ['storageId' => $storage->getId()]); while ($glossaryImport->getStatus() !== 'finished') { $glossaryImport = $crowdin->glossary->getImport($glossary->getId(), $glossaryImport->getIdentifier()); sleep(2); } $glossary = $crowdin->glossary->get($glossary->getId()); print_r($glossary->getData()); ``` -------------------------------- ### Install Crowdin PHP Client Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/README.md Install the Crowdin PHP client using Composer. Ensure you have PHP version 7.1 or higher. ```console composer require crowdin/crowdin-api-client ``` -------------------------------- ### Query Projects and Files using GraphQL API Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/README.md Example of querying project and file information using the GraphQL API. The query specifies a limit for the number of projects and files to retrieve. ```php $query = 'query($limit: Int) { viewer { projects(first: $limit) { edges { node { name files(first: $limit) { totalCount edges { node { name type } } } } } } } }'; $response = $crowdin->graphql->query($query, null, ['limit' => 10]); ``` -------------------------------- ### Create Directory using REST API Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/README.md Example of creating a new directory within a Crowdin project using the REST API. Requires project ID and directory name. ```php $directory = $crowdin->directory->create( , ['name'=> 'My Directory'] ); ``` -------------------------------- ### Delete Directory using REST API Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/README.md Example of deleting a directory from a Crowdin project using the REST API. Requires the project ID and the directory's ID. ```php $crowdin->directory->delete($directory->getProjectId(), $directory->getId()); ``` -------------------------------- ### Create and Upload Translation Memory Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/EXAMPLES.md This example covers creating a new Translation Memory (TM) and then importing TMX file content into it. It polls the import status until completion. The organization parameter is optional for Crowdin Enterprise. ```php use CrowdinApiClient\Crowdin; $crowdin = new Crowdin([ 'access_token' => '', 'organization' => '', // if you use Crowdin Enterprise ]); $tm = $crowdin->translationMemory->create(['name' => 'Test Translation Memory', 'languageId' => 'en']); $storage = $crowdin->storage->create(new SplFileInfo('')); $tmImport = $crowdin->translationMemory->import($tm->getId(), $storage->getId()); while ($tmImport->getStatus() !== 'finished') { $tmImport = $crowdin->translationMemory->checkImportStatus($tm->getId(), $tmImport->getIdentifier()); sleep(2); } $tm = $crowdin->translationMemory->get($tm->getId()); print_r($tm->getData()); ``` -------------------------------- ### Edit Directory using REST API Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/README.md Example of updating an existing directory's title using the REST API. The directory object must be fetched or created first. ```php $directory->setTitle('My Title'); $crowdin->directory->update($directory); ``` -------------------------------- ### Update File in Crowdin Project Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/EXAMPLES.md This example demonstrates how to update an existing file in your Crowdin project with new content. You will need the project ID, file ID, and the path to the updated file. The organization parameter is optional for Crowdin Enterprise. ```php use CrowdinApiClient\Crowdin; $crowdin = new Crowdin([ 'access_token' => '', 'organization' => '', // if you use Crowdin Enterprise ]); $storage = $crowdin->storage->create(new SplFileInfo('')); $file = $crowdin->file->update($projectId, '', ['storageId' => $storage->getId()]); print_r($file->getData()); ``` -------------------------------- ### Preview Documentation Locally Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/CONTRIBUTING.md Serve the generated documentation locally using PHP's built-in web server. Access the documentation at http://127.0.0.1:8080. ```bash php -S 127.0.0.1:8080 -t .phpdoc/build ``` -------------------------------- ### Build Project and Download Translated Files Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/EXAMPLES.md This snippet shows how to initiate a project build and then download the translated files once the build is complete. It includes a loop to poll the build status. The organization parameter is optional for Crowdin Enterprise. ```php use CrowdinApiClient\Crowdin; $crowdin = new Crowdin([ 'access_token' => '', 'organization' => '', // if you use Crowdin Enterprise ]); $projectId = ''; $projectBuild = $crowdin->translation->buildProject($projectId); while ($projectBuild->getStatus() !== 'finished') { $projectBuild = $crowdin->translation->getProjectBuildStatus($projectId, $projectBuild->getId()); sleep(2); } $buildArchive = $crowdin->translation->downloadProjectBuild($projectId, $projectBuild->getId()); print_r($buildArchive->getData()); ``` -------------------------------- ### Generate Project Documentation Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/CONTRIBUTING.md Generate API documentation using phpDocumentor. This command scans the 'src' directory for code and generates documentation files. ```bash php phpDocumentor.phar -d src ``` -------------------------------- ### Run All Unit Tests Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/CONTRIBUTING.md Execute all unit tests for the project using the PHPUnit command-line tool. Ensure all tests pass before submitting changes. ```bash vendor/bin/phpunit ``` -------------------------------- ### Export and Download Glossary Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/EXAMPLES.md This snippet demonstrates exporting a glossary and then downloading the resulting TBX file. It includes polling for the export status. The organization parameter is optional for Crowdin Enterprise. ```php use CrowdinApiClient\Crowdin; $crowdin = new Crowdin([ 'access_token' => '', 'organization' => '', // if you use Crowdin Enterprise ]); $glossaryId = ''; $glossaryExport = $crowdin->glossary->export($glossaryId); while ($glossaryImport->getStatus() !== 'finished') { $glossaryExport = $crowdin->glossary->getExport($glossaryId, $glossaryExport->getIdentifier()); sleep(2); } $tbxFile = $crowdin->glossary->download($glossaryId, $glossaryExport->getIdentifier()); print_r($tbxFile->getData()); ``` -------------------------------- ### Download phpDocumentor Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/CONTRIBUTING.md Download the phpDocumentor.phar executable using wget. This tool is required for generating project documentation. ```bash wget https://phpdoc.org/phpDocumentor.phar ``` -------------------------------- ### Initialize Crowdin API Client Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/README.md Instantiate and configure the Crowdin API client with your access token. An organization domain is optional for Crowdin Enterprise users. ```php use CrowdinApiClient\Crowdin; $crowdin = new Crowdin([ 'access_token' => '', 'organization' => '', // optional ]); ``` -------------------------------- ### Run Specific Unit Test Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/CONTRIBUTING.md Execute a specific unit test file, useful for targeted testing during development. Replace the file path with the desired test file. ```bash vendor/bin/phpunit tests/CrowdinApiClient/Model/ProjectTest.php ``` -------------------------------- ### Export and Download Translation Memory Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/EXAMPLES.md This snippet demonstrates how to export a Translation Memory (TM) and then download the exported TMX file. It includes polling for the export status. The organization parameter is optional for Crowdin Enterprise. ```php use CrowdinApiClient\Crowdin; $crowdin = new Crowdin([ 'access_token' => '', 'organization' => '', // if you use Crowdin Enterprise ]); $tmId = ''; $tmExport = $crowdin->translationMemory->export($tmId); while ($tmExport->getStatus() !== 'finished') { $tmExport = $crowdin->translationMemory->checkExportStatus($tmId, $tmExport->getIdentifier()); sleep(2); } $tmxFile = $crowdin->translationMemory->download($tmId, $tmExport->getIdentifier()); print_r($tmxFile->getData()); ``` -------------------------------- ### Upload File to Crowdin Project Source: https://github.com/crowdin/crowdin-api-client-php/blob/master/EXAMPLES.md Use this snippet to upload a new file to your Crowdin project. Ensure you have the file path and desired file name ready. The organization parameter is optional and used for Crowdin Enterprise. ```php use CrowdinApiClient\Crowdin; $crowdin = new Crowdin([ 'access_token' => '', 'organization' => '', // if you use Crowdin Enterprise ]); $storage = $crowdin->storage->create(new SplFileInfo('')); $file = $crowdin->file->create($projectId, ['storageId' => $storage->getId(), 'name' => '']); print_r($file->getData()); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.