@@ -217,9 +217,14 @@ public function source() {
217217 * @return void
218218 */
219219 public function extract (ExtractService $ extractService ) {
220+ $ projectId = $ this ->Translation ->currentProjectId ();
221+ if (!$ projectId ) {
222+ throw new NotFoundException (__d ('translate ' , 'No project selected. ' ));
223+ }
224+
220225 // Get locale path for display
221226 $ TranslateProjects = $ this ->fetchTable ('Translate.TranslateProjects ' );
222- $ project = $ TranslateProjects ->get ($ this -> Translation -> currentProjectId () );
227+ $ project = $ TranslateProjects ->get ($ projectId );
223228 $ projectPath = $ project ->path ?? null ;
224229 if (!$ projectPath ) {
225230 $ projectPath = ROOT ;
@@ -231,7 +236,7 @@ public function extract(ExtractService $extractService) {
231236 // Set the locale path on the service
232237 $ extractService ->setLocalePath ($ localePath );
233238
234- $ translateLocales = $ this ->TranslateStrings ->TranslateTerms ->TranslateLocales ->getExtractableAsList ($ this -> Translation -> currentProjectId () );
239+ $ translateLocales = $ this ->TranslateStrings ->TranslateTerms ->TranslateLocales ->getExtractableAsList ($ projectId );
235240 $ poFileLanguages = $ extractService ->getPoFileLanguages ();
236241
237242 // Filter to only include files that actually exist
@@ -269,7 +274,7 @@ public function extract(ExtractService $extractService) {
269274 }
270275 $ translations = $ extractService ->extractPotFile ($ domain );
271276
272- $ translationDomain = $ this ->TranslateStrings ->TranslateDomains ->getDomain ($ this -> Translation -> currentProjectId () , $ domain );
277+ $ translationDomain = $ this ->TranslateStrings ->TranslateDomains ->getDomain ($ projectId , $ domain );
273278
274279 foreach ($ translations as $ translation ) {
275280 $ total ++;
@@ -305,7 +310,7 @@ public function extract(ExtractService $extractService) {
305310 $ languageName ,
306311 $ locale ,
307312 $ lang ,
308- $ this -> Translation -> currentProjectId () ,
313+ $ projectId ,
309314 );
310315 if ($ translateLocale ) {
311316 $ translateLocales [$ lang ] = $ translateLocale ->id ;
@@ -315,7 +320,7 @@ public function extract(ExtractService $extractService) {
315320 }
316321 $ translations = $ extractService ->extractPoFile ($ domain , $ locale );
317322
318- $ translationDomain = $ this ->TranslateStrings ->TranslateDomains ->getDomain ($ this -> Translation -> currentProjectId () , $ domain );
323+ $ translationDomain = $ this ->TranslateStrings ->TranslateDomains ->getDomain ($ projectId , $ domain );
319324
320325 foreach ($ translations as $ translation ) {
321326 $ total ++;
@@ -376,9 +381,14 @@ public function extract(ExtractService $extractService) {
376381 * @return \Cake\Http\Response|null|void
377382 */
378383 public function dump () {
384+ $ projectId = $ this ->Translation ->currentProjectId ();
385+ if (!$ projectId ) {
386+ throw new NotFoundException (__d ('translate ' , 'No project selected. ' ));
387+ }
388+
379389 // Get path from current project
380390 $ TranslateProjects = $ this ->fetchTable ('Translate.TranslateProjects ' );
381- $ project = $ TranslateProjects ->get ($ this -> Translation -> currentProjectId () );
391+ $ project = $ TranslateProjects ->get ($ projectId );
382392
383393 $ path = $ project ->path ?? null ;
384394 if (!$ path ) {
@@ -388,7 +398,7 @@ public function dump() {
388398 }
389399 $ path = rtrim ($ path , DS ) . DS . 'resources ' . DS . 'locales ' . DS ;
390400
391- $ translateLocales = $ this ->TranslateStrings ->TranslateTerms ->TranslateLocales ->getExtractableAsList ($ this -> Translation -> currentProjectId () );
401+ $ translateLocales = $ this ->TranslateStrings ->TranslateTerms ->TranslateLocales ->getExtractableAsList ($ projectId );
392402 /** @var \Translate\Model\Entity\TranslateDomain[] $domains */
393403 $ domains = $ this ->TranslateStrings ->TranslateDomains ->getActive ()->toArray ();
394404
@@ -408,7 +418,7 @@ public function dump() {
408418 [$ lang , $ domain ] = explode ('_ ' , $ domain , 2 );
409419
410420 $ langId = $ this ->TranslateStrings ->TranslateTerms ->TranslateLocales ->find ()->where (['iso2 ' => $ lang ])->firstOrFail ()->id ;
411- $ domainId = $ this ->TranslateStrings ->TranslateDomains ->find ()->where (['name ' => $ domain , 'translate_project_id ' => $ this -> Translation -> currentProjectId () ])->firstOrFail ()->id ;
421+ $ domainId = $ this ->TranslateStrings ->TranslateDomains ->find ()->where (['name ' => $ domain , 'translate_project_id ' => $ projectId ])->firstOrFail ()->id ;
412422 $ translations = $ this ->TranslateStrings ->TranslateTerms ->getTranslations ($ langId , $ domainId )->toArray ();
413423
414424 if (!$ translations ) {
@@ -661,6 +671,10 @@ public function import() {
661671 protected function updateSourceReferences ($ translateString , string $ originalName ): int {
662672 $ updatedCount = 0 ;
663673
674+ if (!$ translateString ->references ) {
675+ return 0 ;
676+ }
677+
664678 // Parse references
665679 $ references = explode (PHP_EOL , $ translateString ->references );
666680 $ path = $ translateString ->translate_domain ->translate_project ->path ?? null ;
@@ -870,9 +884,14 @@ protected function readPoFile(string $fileKey, ExtractService $extractService):
870884 * @return \Cake\Http\Response|null|void
871885 */
872886 public function runExtract () {
887+ $ projectId = $ this ->Translation ->currentProjectId ();
888+ if (!$ projectId ) {
889+ throw new NotFoundException (__d ('translate ' , 'No project selected. ' ));
890+ }
891+
873892 $ TranslateProjects = $ this ->fetchTable ('Translate.TranslateProjects ' );
874893 /** @var \Translate\Model\Entity\TranslateProject $project */
875- $ project = $ TranslateProjects ->get ($ this -> Translation -> currentProjectId () );
894+ $ project = $ TranslateProjects ->get ($ projectId );
876895
877896 $ appPath = $ project ->path ?: null ;
878897 if (!$ appPath ) {
@@ -1108,7 +1127,7 @@ public function runExtract() {
11081127 $ domain = pathinfo ($ file , PATHINFO_FILENAME );
11091128 $ translations = $ extractService ->extractPotFile ($ domain );
11101129 $ translationDomain = $ this ->TranslateStrings ->TranslateDomains ->getDomain (
1111- $ this -> Translation -> currentProjectId () ,
1130+ $ projectId ,
11121131 $ domain ,
11131132 );
11141133
0 commit comments