From 2c5a4d625d1853cb207dfbb73817505831874371 Mon Sep 17 00:00:00 2001 From: Emanuele Panzeri Date: Fri, 13 Jan 2023 15:02:03 +0100 Subject: [PATCH] Fix(deprecations) Fix deprecations in sfMessageSource_Aggregate (#277) * Fix(deprecations) Fix deprecations in sfMessageSource_Aggregate, add return types from implemented sfIMessageSource --- CHANGELOG.md | 1 + lib/i18n/sfMessageSource_Aggregate.class.php | 69 +++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 656732e6d..20c65db4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ CHANGELOG ========= +======= xx/xx/xxxx: Version 1.5.16 -------------------------- diff --git a/lib/i18n/sfMessageSource_Aggregate.class.php b/lib/i18n/sfMessageSource_Aggregate.class.php index 14c89aeea..3270f76d9 100644 --- a/lib/i18n/sfMessageSource_Aggregate.class.php +++ b/lib/i18n/sfMessageSource_Aggregate.class.php @@ -18,8 +18,7 @@ */ class sfMessageSource_Aggregate extends sfMessageSource { - protected - $messageSources = array(); + protected $messageSources = array(); /** * Constructor. @@ -46,6 +45,12 @@ public function setCulture($culture) } } + /** + * Gets the last modified unix-time for this particular catalogue+variant. + * + * @param string $source catalogue+variant + * @return int last modified in unix-time format. + */ protected function getLastModified($sources) { $lastModified = time(); @@ -60,6 +65,12 @@ protected function getLastModified($sources) return $lastModified; } + /** + * Determines if the source is valid. + * + * @param string $source catalogue+variant + * @return boolean true if valid, false otherwise. + */ public function isValidSource($sources) { foreach ($sources as $source) @@ -75,6 +86,12 @@ public function isValidSource($sources) return false; } + /** + * Gets the source, this could be a filename or database ID. + * + * @param string $variant catalogue+variant + * @return string the resource key + */ public function getSource($variant) { $sources = array(); @@ -86,6 +103,12 @@ public function getSource($variant) return $sources; } + /** + * Loads the message for a particular catalogue+variant. + * This methods needs to implemented by subclasses. + * + * @return array of translation messages. + */ public function &loadData($sources) { $messages = array(); @@ -106,6 +129,13 @@ public function &loadData($sources) return $messages; } + /** + * Gets all the variants of a particular catalogue. + * This method must be implemented by subclasses. + * + * @param string $catalogue catalogue name + * @return array list of all variants for this catalogue. + */ public function getCatalogueList($catalogue) { $variants = array(); @@ -120,6 +150,12 @@ public function getCatalogueList($catalogue) return $variants; } + /** + * Adds a untranslated message to the source. Need to call save() + * to save the messages to source. + * + * @param string $message message to add + */ public function append($message) { // Append to the first message source only @@ -129,6 +165,15 @@ public function append($message) } } + /** + * Updates the translation. + * + * @param string $text the source string. + * @param string $target the new translation string. + * @param string $comments comments + * @param string $catalogue the catalogue of the translation. + * @return boolean true if translation was updated, false otherwise. + */ public function update($text, $target, $comments, $catalogue = 'messages') { // Only update one message source @@ -143,6 +188,13 @@ public function update($text, $target, $comments, $catalogue = 'messages') return false; } + /** + * Deletes a particular message from the specified catalogue. + * + * @param string $message the source message to delete. + * @param string $catalogue the catalogue to delete from. + * @return boolean true if deleted, false otherwise. + */ public function delete($message, $catalogue = 'messages') { $retval = false; @@ -157,6 +209,14 @@ public function delete($message, $catalogue = 'messages') return $retval; } + /** + * Saves the list of untranslated blocks to the translation source. + * If the translation was not found, you should add those + * strings to the translation source via the append() method. + * + * @param string $catalogue the catalogue to add to + * @return boolean true if saved successfuly, false otherwise. + */ public function save($catalogue = 'messages') { $retval = false; @@ -182,6 +242,11 @@ public function getId() return md5($id); } + /** + * Returns a list of catalogue as key and all it variants as value. + * + * @return array list of catalogues + */ public function catalogues() { throw new sfException('The "catalogues()" method is not implemented for this message source.');