Repository: symfony/ux
Pull request #2193 (2024-09-23 06:52:58)

Fixed typo in links to Symfony UX repo
I fixed typo in the links to Symfony UX repo (before: symfony/symfony-ux).
Note: I wasn't able to deal with the "version" variable.

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature? |  no <!-- please update src/**/CHANGELOG.md files -->
| Issues        | <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT

Before :  https://github.com/symfony/symfony-ux/blob/4.4/src/Map/src/Bridge/Leaflet/README.md  (404)
Now : https://github.com/symfony/ux/blob/2.x/src/Map/src/Bridge/Leaflet/README.md
<!--
Replace this notice by a description of your feature/bugfix.
This will help reviewers and should be a good start for the documentation.

Additionally (see https://symfony.com/releases):
 - Always add tests and ensure they pass.
 - For new features, provide some code snippets to help understand usage.
 - Features and deprecations must be submitted against branch main.
 - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry
 - Never break backward compatibility (see https://symfony.com/bc).
-->


Kocal: Thanks!

But note that only the `symfony-ux` part was wrong, `blob/{version}` is fine **but** it looks like `version` is not interpreted correctly by the Symfony docs.

I'm merging, and ask to the appropriate persons for `{version}` :)

Patch:
diff --git a/src/Map/doc/index.rst b/src/Map/doc/index.rst
index 8231ea46..894cf8e3 100644
--- a/src/Map/doc/index.rst
+++ b/src/Map/doc/index.rst
@@ -233,5 +233,5 @@ https://symfony.com/doc/current/contributing/code/bc.html
 .. _StimulusBundle configured in your app: https://symfony.com/bundles/StimulusBundle/current/index.html
 .. _`Google Maps`: https://github.com/symfony/ux-google-map
 .. _`Leaflet`: https://github.com/symfony/ux-leaflet-map
-.. _`Symfony UX Map Google Maps brige docs`: https://github.com/symfony/symfony-ux/blob/{version}/src/Map/src/Bridge/Google/README.md
-.. _`Symfony UX Map Leaflet bridge docs`: https://github.com/symfony/symfony-ux/blob/{version}/src/Map/src/Bridge/Leaflet/README.md
+.. _`Symfony UX Map Google Maps brige docs`: https://github.com/symfony/ux/blob/{version}/src/Map/src/Bridge/Google/README.md
+.. _`Symfony UX Map Leaflet bridge docs`: https://github.com/symfony/ux/blob/{version}/src/Map/src/Bridge/Leaflet/README.md
diff --git a/src/Translator/CHANGELOG.md b/src/Translator/CHANGELOG.md
index 789af7f2..b8d13254 100644
--- a/src/Translator/CHANGELOG.md
+++ b/src/Translator/CHANGELOG.md
@@ -1,9 +1,5 @@
 # CHANGELOG
 
-## 2.20.0
-
--   Add `throwWhenNotFound` function to configure the behavior when a translation is not found.
-
 ## 2.19.0
 
 -   Add configuration to filter dumped translations by domain.
diff --git a/src/Translator/assets/dist/translator.d.ts b/src/Translator/assets/dist/translator.d.ts
index 8d9f73e0..70da6bb4 100644
--- a/src/Translator/assets/dist/translator.d.ts
+++ b/src/Translator/assets/dist/translator.d.ts
@@ -21,7 +21,6 @@ export interface Message<Translations extends TranslationsType, Locale extends L
 }
 export declare function setLocale(locale: LocaleType | null): void;
 export declare function getLocale(): LocaleType;
-export declare function throwWhenNotFound(enabled: boolean): void;
 export declare function setLocaleFallbacks(localeFallbacks: Record<LocaleType, LocaleType>): void;
 export declare function getLocaleFallbacks(): Record<LocaleType, LocaleType>;
 export declare function trans<M extends Message<TranslationsType, LocaleType>, D extends DomainsOf<M>, P extends ParametersOf<M, D>>(...args: P extends NoParametersType ? [message: M, parameters?: P, domain?: RemoveIntlIcuSuffix<D>, locale?: LocaleOf<M>] : [message: M, parameters: P, domain?: RemoveIntlIcuSuffix<D>, locale?: LocaleOf<M>]): string;
diff --git a/src/Translator/assets/dist/translator_controller.js b/src/Translator/assets/dist/translator_controller.js
index 76292583..0dbb5793 100644
--- a/src/Translator/assets/dist/translator_controller.js
+++ b/src/Translator/assets/dist/translator_controller.js
@@ -220,7 +220,6 @@ function getPluralizationRule(number, locale) {
 
 let _locale = null;
 let _localeFallbacks = {};
-let _throwWhenNotFound = false;
 function setLocale(locale) {
     _locale = locale;
 }
@@ -230,9 +229,6 @@ function getLocale() {
         document.documentElement.lang ||
         'en');
 }
-function throwWhenNotFound(enabled) {
-    _throwWhenNotFound = enabled;
-}
 function setLocaleFallbacks(localeFallbacks) {
     _localeFallbacks = localeFallbacks;
 }
@@ -274,10 +270,7 @@ function trans(message, parameters = {}, domain = 'messages', locale = null) {
             return format(translations[locale], parameters, locale);
         }
     }
-    if (_throwWhenNotFound) {
-        throw new Error(`No translation message found with id "${message.id}".`);
-    }
     return message.id;
 }
 
-export { getLocale, getLocaleFallbacks, setLocale, setLocaleFallbacks, throwWhenNotFound, trans };
+export { getLocale, getLocaleFallbacks, setLocale, setLocaleFallbacks, trans };
diff --git a/src/Translator/assets/src/translator.ts b/src/Translator/assets/src/translator.ts
index 0da20f53..78e45646 100644
--- a/src/Translator/assets/src/translator.ts
+++ b/src/Translator/assets/src/translator.ts
@@ -38,7 +38,6 @@ import { format } from './formatters/formatter';
 
 let _locale: LocaleType | null = null;
 let _localeFallbacks: Record<LocaleType, LocaleType> = {};
-let _throwWhenNotFound = false;
 
 export function setLocale(locale: LocaleType | null) {
     _locale = locale;
@@ -53,10 +52,6 @@ export function getLocale(): LocaleType {
     );
 }
 
-export function throwWhenNotFound(enabled: boolean): void {
-    _throwWhenNotFound = enabled;
-}
-
 export function setLocaleFallbacks(localeFallbacks: Record<LocaleType, LocaleType>): void {
     _localeFallbacks = localeFallbacks;
 }
@@ -167,9 +162,5 @@ export function trans<
         }
     }
 
-    if (_throwWhenNotFound) {
-        throw new Error(`No translation message found with id "${message.id}".`);
-    }
-
     return message.id;
 }
diff --git a/src/Translator/doc/index.rst b/src/Translator/doc/index.rst
index 6d194ce4..614f4799 100644
--- a/src/Translator/doc/index.rst
+++ b/src/Translator/doc/index.rst
@@ -98,27 +98,6 @@ By default, the default locale is ``en`` (English) that you can configure throug
 #. Or with ``<html data-symfony-ux-translator-locale="your-locale">`` attribute
 #. Or with ``<html lang="your-locale">`` attribute
 
-Detecting missing translations
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-By default, the translator will return the translation key if the translation is missing.
-
-You can change this behavior by calling ``throwWhenNotFound(true)``:
-
-.. code-block:: diff
-
-      // assets/translator.js
-
-    - import { trans, getLocale, setLocale, setLocaleFallbacks } from '@symfony/ux-translator';
-    + import { trans, getLocale, setLocale, setLocaleFallbacks, throwWhenNotFound } from '@symfony/ux-translator';
-      import { localeFallbacks } from '../var/translations/configuration';
-
-      setLocaleFallbacks(localeFallbacks);
-    + throwWhenNotFound(true)
-
-      export { trans }
-      export * from '../var/translations';
-
 Importing and using translations
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 


Test patch:
diff --git a/src/Translator/assets/test/translator.test.ts b/src/Translator/assets/test/translator.test.ts
index 6df854a1..5a468044 100644
--- a/src/Translator/assets/test/translator.test.ts
+++ b/src/Translator/assets/test/translator.test.ts
@@ -4,7 +4,6 @@ import {
     type NoParametersType,
     setLocale,
     setLocaleFallbacks,
-    throwWhenNotFound,
     trans,
 } from '../src/translator';
 
@@ -12,7 +11,6 @@ describe('Translator', () => {
     beforeEach(() => {
         setLocale(null);
         setLocaleFallbacks({});
-        throwWhenNotFound(false);
         document.documentElement.lang = '';
         document.documentElement.removeAttribute('data-symfony-ux-translator-locale');
     });
@@ -389,40 +387,6 @@ describe('Translator', () => {
             );
         });
 
-        test('missing message should return the message id when `throwWhenNotFound` is false', () => {
-            throwWhenNotFound(false);
-            setLocale('fr');
-
-            const MESSAGE_IN_ANOTHER_DOMAIN: Message<{ security: { parameters: NoParametersType } }, 'en'> = {
-                id: 'Invalid credentials.',
-                translations: {
-                    messages: {
-                        en: 'Invalid credentials.',
-                    },
-                },
-            };
-
-            expect(trans(MESSAGE_IN_ANOTHER_DOMAIN)).toEqual('Invalid credentials.');
-        });
-
-        test('missing message should throw an error if `throwWhenNotFound` is true', () => {
-            throwWhenNotFound(true);
-            setLocale('fr');
-
-            const MESSAGE_IN_ANOTHER_DOMAIN: Message<{ security: { parameters: NoParametersType } }, 'en'> = {
-                id: 'Invalid credentials.',
-                translations: {
-                    messages: {
-                        en: 'Invalid credentials.',
-                    },
-                },
-            };
-
-            expect(() => {
-                trans(MESSAGE_IN_ANOTHER_DOMAIN);
-            }).toThrow(`No translation message found with id "Invalid credentials.".`);
-        });
-
         test('message from intl domain should be prioritized over its non-intl equivalent', () => {
             const MESSAGE: Message<
                 { 'messages+intl-icu': { parameters: NoParametersType }; messages: { parameters: NoParametersType } },