[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX][UX] Language: Add feedback for custom translation saves

Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68913ec33203d_2cd5d047374@gitlab-sidekiq-low-urgency-cpu-bound-v2-58b475bb65-qh4ns.mail>

Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
d7ef16d8 by MAGENE Sem Joel at 2025-08-04T22:32:06+00:00
[FIX][UX] Language: Add feedback for custom translation saves
---
* [FIX][UX] Language: Add feedback for custom translation saves

See merge request tikiwiki/tiki!8029

- - - - -


1 changed file:

- lib/core/Services/Language/Controller.php


Changes:

=====================================
lib/core/Services/Language/Controller.php
=====================================
@@ -170,31 +170,46 @@ class Services_Language_Controller
             $from = $input->asArray('from');
             $to = $input->asArray('to');
 
+            $submittedData = [];
             $isValid = is_array($from)
                 && is_array($to)
                 && count($from) > 0
                 && count($from) === count($to);
 
             if ($isValid) {
-                $data = [];
-
-                //prepare data
+                //prepare data, filtering out empty rows
                 foreach ($from as $index => $source) {
                     if (! empty($to[$index]) && ! empty($source)) {
-                        $data[ $source ] = $to[ $index ];
+                        $submittedData[ $source ] = $to[ $index ];
                     }
                 }
-
-                //write custom php file content
-                $this->utilities->writeCustomPhpTranslations($language, $data);
-
-                //empty cache
+            }
+            // Get the translations that are currently saved to compare against.
+            $existingTranslations = $this->utilities->getCustomPhpTranslations($language);
+            if ($submittedData == $existingTranslations) {
+                // CASE 1: The user clicked save, but made no changes.
+                if (empty($submittedData)) {
+                    // CASE A: The user submitted an empty form, and nothing was saved before.
+                    Feedback::warning(tr('No valid translations were provided to save.'));
+                } else {
+                    // CASE B: The user clicked "Save" without making any changes to existing data.
+                    Feedback::note(tr('No changes were made.'));
+                }
+            } else {
+                // CASE 2: The data is different (add, modify, OR delete). This is a true success.
+                $this->utilities->writeCustomPhpTranslations($language, $submittedData);
                 $cachelib = TikiLib::lib('cache');
                 $cachelib->empty_cache();
 
-                //TODO add success message
+                Feedback::success(tr('Custom translations saved successfully.'));
 
-                //TODO refresh screen
+                return [
+                    'FORWARD' => [
+                        'controller' => 'language',
+                        'action' => 'manage_custom_translations',
+                        'language' => $language,
+                    ]
+                ];
             }
         }
         //get custom translation content



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/d7ef16d858d7715cebf49e95fb8778faef644cb6

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/d7ef16d858d7715cebf49e95fb8778faef644cb6
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.