Find unused resource keys in properties files in a Salesforce Commerce Cloud project and get rid of them.

Overview

Find Unused Resource Keys

Find unused resource keys in properties files in a Salesforce Commerce Cloud project and get rid of them.

It looks through all *.properties files in a specified directory and sub-directories and then proceeds to look through all specified file types in the project looking for each resource key in each line, taking note of each one that is not found. Only found keys are included in the final output, so as a result you have the properties files minus the unused keys.

Preamble

This tool is meant as a one-time check to weed out unused keys before transitioning to the excellent https://github.com/SalesforceCommerceCloud/resource-manager, so that there isn't too much overhead and bloat in terms of unused keys. You might adopt it for use in automatic processes, but I didn't write it with that intention - so do your own tests accordingly before using it.

Since this might touch thousands of keys in hundreds of files, you are advised to sanity check results and always keep backups. I don't want to be responsible for you losing translations over this. :) Though in my tests, no errors of any kind came to my attention.

How to

  1. Install jprops Python package. pip3 install jprops
  2. Clone repository or direct-download the delete-unused-resource-keys.py file from Github.
  3. Put it into a directory above or within the directory containing your properties files. It can only go down on the folder hierarchy, never up.
  4. Open the help page of the tool by executing, on a CLI: delete-unused-resource-keys.py -h. All arguments are explained so you can see what you need.
  5. Example command: python3 delete-unused-resource-keys.py -sd cartridges -td cleaned_properties -l -v, looking through all resource files in the 'cartridges' folder, putting cleaned versions of those into 'cleaned_properties' folder. It also writes a logfile (put in the target directory if given, else next to script file) called 'cleaning_report.txt'. It is also set to verbose, so outputting additional information during runtime.

Notes:

Currently, the tool does not handle duplicate files very well. If you have overloaded properties files in cartridge, i.e. with exact same name but differing contents, the last processed one will win. In this case I recommend using the tool in each cartridge separately. This should also be possible with multiple instances of the script simultaneously, with no issues - just use a different output directory for each instance.

Thanks for the hint, Daniel Anechitoaie

Having -v/--verbose flag lengthens the runtime considerably. If you want to just see what happens, before the actual final run, this is fine. During final run, it makes sense to either not set verbose flag or reroute the output to another file via python3 delete-unused-resource-keys.py -sd some_dir -td another_dir -v > console_output.txt.

Some folders are ignored during lookup. Those are defined in the is_ignored_folder function. There is a simple array inside that function containing folder name fragments. Feel free to change them to suit your needs.

The file types where the script is looking for resource keys is also described in an array called 'lookup_files', defined at the top of the script for convenience. You can just edit the array.

Running this on a multi-language/multi-brand project with hundreds of properties-files (averaging 300-500 lines each) may take 1-2 hrs.

Contribution

If you have a feasible idea for improvement, find my code horrible and want to improve it or just find an error or edge-case that isn't handled yet, feel free to either create a bug ticket here in Github or a pull request fixing the problem. Your contribution will be listed (except you don't want that).

You might also like...
A python app which aggregates and splits costs from multiple public cloud providers into a csv

Cloud Billing This project aggregates the costs public cloud resources by accounts, services and tags by importing the invoices from public cloud prov

A python tool give n number of inputs and parallelly you will get a output by separetely

http-status-finder Hello Everyone!! This is kavisurya, In this tool you can give n number of inputs and parallelly you will get a output by separetely

Simple python module to get the information regarding battery in python.
Simple python module to get the information regarding battery in python.

Battery Stats A python3 module created for easily reading the current parameters of Battery in realtime. It reads battery stats from /sys/class/power_

Python script to get some stats on nodes in a Blender material nodetree

Python script to get some stats on nodes in a Blender material nodetree. It counts the nodes, the node types and the max deep level for group nodes.

A small python tool to get relevant values from SRI invoices
A small python tool to get relevant values from SRI invoices

SriInvoiceProcessing A small python tool to get relevant values from SRI invoices Some useful info to run the tool Login into your SRI account and ret

Color getter (including method to get random color or complementary color) made out of Python

python-color-getter Color getter (including method to get random color or complementary color) made out of Python Setup pip3 install git+https://githu

Utility to extract Fantasy Grounds Unity Line-of-sight and lighting files from a Univeral VTT file exported from Dungeondraft
Utility to extract Fantasy Grounds Unity Line-of-sight and lighting files from a Univeral VTT file exported from Dungeondraft

uvtt2fgu Utility to extract Fantasy Grounds Unity Line-of-sight and lighting files from a Univeral VTT file exported from Dungeondraft This program wo

A simple language and reference decompiler/compiler for MHW THK Files
A simple language and reference decompiler/compiler for MHW THK Files

Leviathon A simple language and reference decompiler/compiler for MHW THK Files. Project Goals The project aims to define a language specification for

iOS Snapchat parser for chats and cached files

ParseSnapchat iOS Snapchat parser for chats and cached files Tested on Windows and Linux install required libraries: pip install -r requirements.txt c

Owner
Noël
Noël
This tool analyzes the json files generated by stream-lnd-htlcs to find hidden channel demand.

analyze_lnd_htlc Introduction Rebalancing channels is an important part of running a Lightning Network node. While it would be great if all channels c

Marimox 4 Dec 8, 2022
This code renames subtitle file names to your video files names, so you don't need to rename them manually.

Rename Subtitle This code renames your subtitle file names to your video file names so you don't need to do it manually Note: It only works for series

Mostafa Kazemi 4 Sep 12, 2021
Find dependent python scripts of a python script in a project directory.

Find dependent python scripts of a python script in a project directory.

null 2 Dec 5, 2021
A python lib for generate random string and digits and special characters or A combination of them

A python lib for generate random string and digits and special characters or A combination of them

Torham 4 Nov 15, 2022
A python package for your Kali Linux distro that find the fastest mirror and configure your apt to use that mirror

Kali Mirror Finder Using Single Python File A python package for your Kali Linux distro that find the fastest mirror and configure your apt to use tha

MrSingh 6 Dec 12, 2022
Find version automatically based on git tags and commit messages.

GIT-CONVENTIONAL-VERSION Find version automatically based on git tags and commit messages. The tool is very specific in its function, so it is very fl

null 0 Nov 7, 2021
A python program to find binary, octal and hexadecimal of a decimal.

decimal-converter This little python program can convert a decimal in to, Binary Octal Hexadecimal Needed Python 3 or later or a online python compile

Chandula Janith 0 Nov 27, 2021
Here, I find the Fibonacci Series using python

Fibonacci-Series-using-python Here, I find the Fibonacci Series using python Requirements No Special Requirements Contribution I have strong belief on

Sachin Vinayak Dabhade 4 Sep 24, 2021
Rabbito is a mini tool to find serialized objects in input values

Rabbito-ObjectFinder Rabbito is a mini tool to find serialized objects in input values What does Rabbito do Rabbito has the main object finding Serial

null 7 Dec 13, 2021
cssOrganizer - organize a css file by grouping them into categories

This python project was created to scan through a CSS file and produce a more organized CSS file by grouping related CSS Properties within selectors. Created in my spare time for fun and my own utility. It takes in a style.css file and creates a file called 'organized-style.css.

Andrew Espindola 0 Aug 31, 2022