-
-
Save jpingo/9c1b7cd361ca0d53f3a5 to your computer and use it in GitHub Desktop.
Language Translation problem using PAPI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function testtranslateArticleTwice() | |
{ | |
//Loaded services | |
$languageService = $this->repo->getContentLanguageService(); | |
$contentTypeService = $this->repo->getContentTypeService(); | |
$contentService = $this->repo->getContentService(); | |
$locationService = $this->repo->getLocationService(); | |
$urlAliasService = $this->repo->getURLAliasService(); | |
//Create FRE Language | |
$languageCreateStructFre = $languageService->newLanguageCreateStruct(); | |
$languageCreateStructFre->languageCode = 'fre-FR'; | |
$languageCreateStructFre->name = 'French (France)'; | |
$languageCreateStructFre->enabled = true; | |
$languageService->createLanguage( $languageCreateStructFre ); | |
//Create Nor Language | |
$languageCreateStructNor = $languageService->newLanguageCreateStruct(); | |
$languageCreateStructNor->languageCode = 'nor-NO'; | |
$languageCreateStructNor->name = 'Norwegian (Bokmal)'; | |
$languageCreateStructNor->enabled = true; | |
$languageService->createLanguage($languageCreateStructNor); | |
//Create Folder News | |
$contentTypeFolder = $contentTypeService->loadContentTypeByIdentifier( 'folder' ); | |
$contentCreateStruct = $contentService->newContentCreateStruct( $contentTypeFolder, 'eng-GB' ); | |
$contentCreateStruct->setField ( 'name', 'News' ); | |
$locationCreateStruct = $locationService->newLocationCreateStruct( 2 ); | |
$draft = $contentService->createContent( $contentCreateStruct, array( $locationCreateStruct ) ); | |
$contentService->publishVersion( $draft->versionInfo ); | |
//Create Article Eng | |
$contentTypeArticle = $contentTypeService->loadContentTypeByIdentifier( 'article' ); | |
$contentCreateStruct2 = $contentService->newContentCreateStruct( $contentTypeArticle, 'eng-GB' ); | |
$contentCreateStruct2->setField ( 'title', 'Article Eng', 'eng-GB' ); | |
$contentCreateStruct2->setField( | |
"intro", | |
'<?xml version="1.0" encoding="utf-8"?> | |
<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/" | |
xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/" | |
xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"> | |
<paragraph xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/"> | |
This is a eng-GB article | |
</paragraph> | |
</section>', | |
"eng-GB" | |
); | |
$alias = $urlAliasService->lookup( '/News', 'eng-GB' ); | |
$loadedLocation = $locationService->loadLocation( $alias->destination ); | |
$locationCreateStruct2 = $locationService->newLocationCreateStruct( $loadedLocation->id ); | |
$draft2 = $contentService->createContent( $contentCreateStruct2, array( $locationCreateStruct2 ) ); | |
$contentService->publishVersion( $draft2->versionInfo ); | |
//Update Article in fre-FR | |
$aliasEng = $urlAliasService->lookup("/News/Article-Eng", 'eng-GB'); | |
$loadedLocationEng = $locationService->loadLocation( $aliasEng->destination ); | |
$contentInfoFre = $loadedLocationEng->getContentInfo(); | |
$contentUpdateStructFre = $contentService->newContentUpdateStruct(); | |
$contentUpdateStructFre->initialLanguageCode = 'eng-GB'; | |
$contentUpdateStructFre->setField( 'title', 'Article Fre', 'fre-FR'); | |
$contentUpdateStructFre->setField( | |
"intro", | |
'<?xml version="1.0" encoding="utf-8"?> | |
<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/" | |
xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/" | |
xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"> | |
<paragraph xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/"> | |
This is a fre-FR article | |
</paragraph> | |
</section>', | |
"fre-FR" | |
); | |
$contentDraftFre = $contentService->createContentDraft( $contentInfoFre ); | |
$newContentDraftFre = $contentService->updateContent( $contentDraftFre->versionInfo, $contentUpdateStructFre ); | |
$contentService->publishVersion( $newContentDraftFre->versionInfo ); | |
//Update Article in nor-Nor | |
$aliasEng2 = $urlAliasService->lookup("/News/Article-Eng", 'eng-GB'); | |
$loadedLocationEng2 = $locationService->loadLocation( $aliasEng2->destination ); | |
$contentInfoNor = $loadedLocationEng2->getContentInfo(); | |
$contentUpdateStructNor = $contentService->newContentUpdateStruct(); | |
$contentUpdateStructNor->initialLanguageCode = 'eng-GB'; | |
$contentUpdateStructNor->setField( 'title', 'Article Nor', 'nor-NO'); | |
$contentUpdateStructNor->setField( | |
"intro", | |
'<?xml version="1.0" encoding="utf-8"?> | |
<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/" | |
xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/" | |
xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"> | |
<paragraph xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/"> | |
This is a nor-NO article | |
</paragraph> | |
</section>', | |
"nor-NO" | |
); | |
$contentDraftNor = $contentService->createContentDraft( $contentInfoNor ); | |
$newContentDraftNor = $contentService->updateContent( $contentDraftNor->versionInfo, $contentUpdateStructNor ); | |
$contentService->publishVersion( $newContentDraftNor->versionInfo ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment