Snip-snap is a command-line tool that localizes Kindle clippings exported from devices in different languages into English. It parses the clippings file and converts date formats, page numbers, and location information into a consistent English format.
This project was written entirely via Aider, an AI-powered coding assistant.
Snip.Snap.The.Office.from.Discord.mp4
This is an experiment where I'm limiting myself to using only AI tools to write and improve code in an effort to improve how I think and work with AI tools.
I started with a problem I had: using my Kindle in Japanese and English led to both languages used in 'My Clippings.txt', where highlights are stored. This is a problem when the services I use to parse the highlights support only English formats. This section in the README is the only part of the codebase written by hand.
I welcome contributions, fixes, new languages, and requests to localize into languages beyond English. Although not a requirement, I'd like to challenge you to use AI as well in your contributions - let's see how far we can go ✨
- Parses Kindle clippings exported in Japanese.
- Localizes page numbers, location ranges, and dates into English.
- Supports a plugin architecture for adding more languages.
Note: Currently, the tool assumes that all clippings will be localized into English. Support for other target languages may be added in the future.
To run the localizer, use the following command:
bun run src/index.ts <inputFilePath> <languageCode><inputFilePath>: Path to the.txtclippings file exported from your Kindle device.<languageCode>: Language code of the clippings file (e.g.,jafor Japanese).
Example:
bun run index.ts my_clippings.txt jaThis will generate a new file named my_clippings_localized.txt with the localized content.
Input (examples/My Clippings.txt):
How to Take Smart Notes: One Simple Technique to Boost Writing, Learning and Thinking (Ahrens, Sönke)
- 55ページ|位置No. 863-865のハイライト |作成日: 2024年1月9日火曜日 23:25:35
The same goes for writing permanent notes, which have another feedback loop built-in: Expressing our own thoughts in writing makes us realise if we really thought them through. The moment we try to combine them with previously written notes, the system will unambiguously show us contradictions, inconsistencies and repetitions.
==========
Output (examples/My Clippings_localized.txt):
How to Take Smart Notes: One Simple Technique to Boost Writing, Learning and Thinking (Ahrens, Sönke)
- Your Highlight on page 55 | Location 863-865 | Added on Tuesday, January 9, 2024 11:25:35 PM
The same goes for writing permanent notes, which have another feedback loop built-in: Expressing our own thoughts in writing makes us realise if we really thought them through. The moment we try to combine them with previously written notes, the system will unambiguously show us contradictions, inconsistencies and repetitions.
==========
This example is taken directly from the examples directory and shows a real transformation performed by the tool. It demonstrates the localization of page numbers, location information, and date/time formatting from Japanese to English.
- Bun - A fast all-in-one JavaScript runtime.
First, ensure you have Bun installed. If not, you can install it from the official website.
Clone the repository and navigate to the project directory:
git clone <repository-url>
cd snip-snapInstall the dependencies:
bun install- Japanese (
ja)
The tool uses a localization strategy pattern, allowing support for multiple languages. Currently, only Japanese is supported, but contributions are welcome to add more languages.
To run the test suite:
bun testThis will execute the tests defined in index.test.ts, ensuring that the localization functions work as expected.
To add support for another language:
-
Create a New Localization Strategy:
- Add a new file in the
localization/plugins/directory, e.g.,SpanishLocalization.ts. - Implement the
BaseLocalizationStrategyabstract class.
- Add a new file in the
-
Update the Localization Factory:
-
Modify
LocalizationFactory.tsto include your new strategy.import SpanishLocalization from './plugins/SpanishLocalization'; // ... switch (languageCode) { case 'es': return new SpanishLocalization(); // ... }
-
-
Add Test Cases:
- Create test cases in
index.test.tsto ensure your localization strategy works correctly.
- Create test cases in