From c342755736eb1f3715f9de3c5bc46f0341e102b7 Mon Sep 17 00:00:00 2001 From: Tien Do Nam <38380847+Tienisto@users.noreply.github.com> Date: Sat, 22 Jun 2024 23:01:46 +0200 Subject: [PATCH] fix: analyze should respect linked translations (#228) --- slang/lib/src/runner/analyze.dart | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/slang/lib/src/runner/analyze.dart b/slang/lib/src/runner/analyze.dart index fab27e32..6f702dd8 100644 --- a/slang/lib/src/runner/analyze.dart +++ b/slang/lib/src/runner/analyze.dart @@ -331,7 +331,18 @@ void _getUnusedTranslationsInSourceCodeRecursive({ ); } else { final translationCall = '$translateVar.${child.path}'; - if (!sourceCode.contains(translationCall)) { + const linkedPrefix = r'${_root'; + + // We only need to check if the translateVar is not part of the linked string. + // Since most developers use the default "t" as translateVar, + // we can ignore the linked call because it is already covered by the translateVar. + final linkedCall = linkedPrefix.endsWith(translateVar) + ? null + : '$linkedPrefix.${child.path}'; + + final isUsed = sourceCode.contains(translationCall) || + (linkedCall != null && sourceCode.contains(linkedCall)); + if (!isUsed) { // add whole base node which is expected _addNodeRecursive( node: child,