@@ -28,6 +28,7 @@ public function register($category, $path, $mainContextId = null)
2828 if ($ success and $ this ->getEnabled ($ mainContextId )) {
2929 HookRegistry::register ('Template::Workflow ' , array ($ this , 'addWorkflowModifications ' ));
3030 HookRegistry::register ('TemplateManager::display ' , array ($ this , 'loadResourcesToWorkflow ' ));
31+ HookRegistry::register ('TemplateManager::display ' , array ($ this , 'filterTranslationsByLocale ' ));
3132 HookRegistry::register ('Templates::Article::Main ' , array ($ this , 'addPublicSiteModifications ' ));
3233 HookRegistry::register ('Templates::Issue::Issue::Article ' , array ($ this , 'addPublicSiteModifications ' ));
3334 HookRegistry::register ('Dispatcher::dispatch ' , array ($ this , 'setupDoiForTranslationHandler ' ));
@@ -146,6 +147,41 @@ public function loadResourcesToWorkflow($hookName, $params)
146147 return false ;
147148 }
148149
150+ public function filterTranslationsByLocale ($ hookName , $ params )
151+ {
152+ $ templateMgr = $ params [0 ];
153+ $ template = $ params [1 ];
154+
155+ if ($ template != 'frontend/pages/issue.tpl ' && $ template != 'frontend/pages/indexJournal.tpl ' ) {
156+ return false ;
157+ }
158+
159+ $ publishedSubmissions = $ templateMgr ->getTemplateVars ('publishedSubmissions ' );
160+ $ locale = $ templateMgr ->getTemplateVars ('locale ' );
161+ $ translationsService = new TranslationsService ();
162+
163+ foreach ($ publishedSubmissions as $ sectionId => $ section ) {
164+ if (empty ($ section ['articles ' ])) {
165+ continue ;
166+ }
167+
168+ $ publishedSubmissions [$ sectionId ]['articles ' ] = array_values (
169+ array_filter ($ section ['articles ' ], function ($ submission ) use ($ locale , $ translationsService ) {
170+ if ($ submission ->getData ('isTranslationOf ' )) {
171+ return $ submission ->getLocale () == $ locale ;
172+ }
173+
174+ $ translations = $ translationsService ->getTranslations ($ submission ->getId (), 'article ' );
175+ return !in_array ($ locale , array_column ($ translations , 'locale ' ));
176+ }
177+ ));
178+ }
179+
180+ $ templateMgr ->assign ('publishedSubmissions ' , $ publishedSubmissions );
181+
182+ return false ;
183+ }
184+
149185 private function addCreateTranslationForm ($ templateMgr , $ request )
150186 {
151187 $ context = $ request ->getContext ();
0 commit comments