Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Ensure the '_' i18n function keeps its name when built #1097

Merged
merged 1 commit into from
May 28, 2021

Conversation

bbecquet
Copy link
Contributor

Description

Specify in the Webpack optimization config to not mangle (ie. replace by a generated name) the _ identifier, as it is used by the i18n script to spot translation strings in the bundle by analyzing the code.
This uses the config of Terser (doc: https://github.com/terser/terser#mangle-options), the tool used by default by Webpack to optimize production code.

Why

Since #1088, some files use this function as exposed by a React hook, not as a global function. Translation strings used in this file were not part of the i18n extract anymore, because the _ const was renamed by Terser.
Global identifiers are not mangled by default, which explains it didn't need a special config until now.

Comparison

In public/build/javascript/bundle.js

Before After
Capture d’écran de 2021-05-28 14-52-05 Capture d’écran de 2021-05-28 14-50-23

@bbecquet bbecquet requested a review from amatissart May 28, 2021 12:52
@bbecquet bbecquet merged commit 24ede07 into Qwant:master May 28, 2021
@bbecquet bbecquet deleted the fix-i18n-string-extract branch May 28, 2021 13:08
@bbecquet bbecquet mentioned this pull request May 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants