Code Monkey home page Code Monkey logo

translations_cleaner's Introduction

translations_cleaner

Dart package to search and delete unused translations from .arb files, for all languages, all in one go.

NOTE : This package has been developed keeping flutter_localizations package in mind, which uses .arb files for all translations.

Package in action

Usage

# Add translations_cleaner as a dev dependency
dart pub add --dev translations_cleaner

dart run translations_cleaner <command> [arguments]
# OR
flutter pub run translations_cleaner <command> [arguments]

Commands Available

  • clean-translations - Search all the translations listed in arb files and delete the unused translations
  • list-unused-terms - Search all the translations listed in arb files and print/save a list of unused translations.

Options Available

Available only for list-unused-terms

  • -a, --[no-]abort-on-unused - Abort execution if unused translations are found. This can be helpful in CI, if you don't want to proceed if a build should fail.

Available for both commands

  • -h, --help - Print this usage information.
  • -o, --output-path - Path for saving exported file, defaults to root path of the folder
  • -e, --[no-]export - Save unused keys as a .txt file in the path provided

Why ๐Ÿค”

Translations can be a very time taking process when the app starts to scale and there are a lot many translations. Hence it is a good practice to clean the translations if it is not being used. Checking for unused translations is tedious, hence this package.

How ๐Ÿค–

  • translations_cleaner looks for all the .arb files located in the directory, and fetches all the translations, from all the languages.
  • Then it looks for all the .dart files.
  • All the translation terms are looked for in these dart files
  • The translations not found in the dart files are removed from the corresponding .arb files, including any attributes as well

Limitations ๐Ÿ˜”

  • This package currently works only for l10n achieved via flutter_localizations, which uses .arb files.
  • There are other l10n packages which use .json and .yaml for saving translations. These are not supported currently

translations_cleaner's People

Contributors

chinmay-kb avatar

Stargazers

 avatar Pritish Samal avatar  avatar

Watchers

 avatar

translations_cleaner's Issues

Keys falsely detected as unused

I have a project that includes a flutter package in a subfolder. This package is also localized and has its own arb files aside from the main app. The keys listed in the package are all used but they are listed as unused by translations_cleaner. I would expect either to properly detect them as used (in the package) or to have an option to ignore those or only search for arb files that belong to the package where the command runs from.

Unhandled exception: FormatException: Unexpected character

dart run translations_cleaner list-unused-terms
FETCHING ALL THE TRANSLATION TERMS ๐ŸŒ
Unhandled exception:
FormatException: Unexpected character (at line 331, character 1)
}
^

#0      _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1383:5)
#1      _ChunkedJsonParser.parse (dart:convert-patch/convert_patch.dart:907:13)
#2      _parseJson (dart:convert-patch/convert_patch.dart:35:10)
#3      JsonDecoder.convert (dart:convert/json.dart:610:36)
#4      JsonCodec.decode (dart:convert/json.dart:216:41)
#5      jsonDecode (dart:convert/json.dart:155:10)
#6      getTranslationTerms (package:translations_cleaner/src/translation_terms.dart:20:17)
#7      findUnusedTerms (package:translations_cleaner/src/unused_terms.dart:11:17)
#8      ListUnusedTranslations.run (file:///Users/intraector/.pub-cache/hosted/pub.dev/translations_cleaner-0.0.5/bin/commands/list_unused_translations.dart:38:21)
#9      CommandRunner.runCommand (package:args/command_runner.dart:212:27)
#10     CommandRunner.run.<anonymous closure> (package:args/command_runner.dart:122:25)
#11     new Future.sync (dart:async/future.dart:302:31)
#12     CommandRunner.run (package:args/command_runner.dart:122:14)
#13     main (file:///Users/intraector/.pub-cache/hosted/pub.dev/translations_cleaner-0.0.5/bin/translations_cleaner.dart:13:7)
#14     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:33)
#15     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)

intl_ru.arb.txt

Not working with the project with many packages

I have a project structure like that:

my_app
โ”œโ”€โ”€ l10n_package
โ”œโ”€โ”€ package_using_l10n
โ”œโ”€โ”€ package_also_using_l10n

I have all localization-related files in l10n_package. I export the AppLocalizations class from l10n_package to other packages.

I tried to use translation_cleaner, but it deletes all my translations :(

Keys not detected as unused

I have a few keys which are not detect as unused.
One example in app_en.arb:

...
"restorePurchases": "RESTORE PURCHASES",
...

The reason is that in my code there is a function named restorePurchasesAsync();. Just because the function's name contains the key, it is enough to classify it as "used" which is obviously wrong. Even if I comment out the method I still get the same behaviour.

Not detecting unused keys

In our project it is not marking unused key as being unused. We've got a bit of an advanced project setup. Maybe that is why it is failing.

Note: Would not mind fixing the issue myself if you could let me know how I can debug the commands agains our projects code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.