Skip to main content
# Android-Strings-Format

This script takes a strings resource as a model and a second one as a target.
It will format the target strings resource in order to keep the same tags and comments order as the model one.
Be aware that the target strings resource will be overwritten if no output file has been specified.
The script will also warn you if a resource is missing inside the target strings.xml file.

You need to run this script inside of the res directory of your Android project.
Example of usage: python android-strings-format.py --target fr --output formatted_strings.xml

## Usage

android-strings-format.py [-h] [-m MODEL] -t TARGET
[-o OUTPUT]

* -h, --help show this help message and exit

* --model MODEL, -m MODEL
Language code of the strings resource to use as model.
If not specified, strings.xml inside the default
values directory will be used as the model.

* --target TARGET, -t TARGET
Language code of the strings resource to format

* --output OUTPUT, -o OUTPUT
Path to the output formatted strings resource. If not
specified, the target strings resource file will be
overwritten.

## Example

Target inside values directory
```
<?xml version="1.0" encoding="utf-8"?>

<!--
Copyright 2016 Jonathan Odul
Blablablabla
-->

<resources>
<!-- Application name -->
<string name="app_name">APP</string>

<!-- Dialog texts -->
<string name="loading">Loading…</string>
<string name="loading_data">Loading data…</string>
<string name="processing">Processing…</string>
<string name="please_wait">Please wait…</string>

<!-- Dialog button texts -->
<string name="ok">Ok</string>
<string name="refresh">Refresh</string>
<string name="cancel">Cancel</string>
<string name="quit">Quit</string>

<!-- Error message -->
<string name="no_sdcard">No SD card mounted.
\nPlease mount a sd card to use this application.</string>

<!-- Modes -->
<string-array name="modes">
<item>Single</item>
<item>Shuffle</item>
<item>Repeat</item>
</string-array>

<!-- Plurals: time_minute -->
<plurals name="time_minute">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>

</resources>
```

Model inside values-fr directory
```
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Resources not formatted. What a disaster -->
<string name="app_name">VG Music</string>

<string name="loading">
Chargement en cours…</string>
<string name="loading_data">Chargement des données…</string>

<string name="before_leaving">Avant de partir…</string>
<string name="no_sdcard">Aucune carte SD détéctée.
\nVeuillez obtenir une carte SD avant d\'utiliser cette application.</string>

<string name="cancel">Annuler</string>
<string name="quit">Quitter</string>
<!-- Modes -->
<string-array name="modes">
<item>Simple</item>
<item>Aléatoire</item>
<item>Répétition</item>
</string-array>

<string name="processing">Traitement en cours…</string>
<string name="please_wait">Veuillez patienter quelques instants…</string>

<!-- Plurals: time_minute -->
<plurals name="time_minute">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>

<string name="refresh">Rafraîchir</string>

<!-- To be deleted -->
<string name="unused_resource">Omelette du fromage</string>
</resources>
```

Running command
```
python android-strings-format.py --target fr --output formatted_strings.xml
```

Output
```
Processing with...
model: values/strings.xml
target: values-fr/strings.xml
Warning: resource 'ok' does not exist inside values-fr/strings.xml
Saved formatted strings resource to: formatted_strings.xml
```

formatted_strings.xml
```
<?xml version='1.0' encoding='UTF-8'?>
<!--
Copyright 2016 Jonathan Odul
Blablablabla
-->
<resources>
<!-- Application name -->
<string name="app_name">VG Music</string>

<!-- Dialog texts -->
<string name="loading">
Chargement en cours…</string>
<string name="loading_data">Chargement des données…</string>
<string name="processing">Traitement en cours…</string>
<string name="please_wait">Veuillez patienter quelques instants…</string>

<!-- Dialog button texts -->
<string name="ok">Ok</string>
<string name="refresh">Rafraîchir</string>
<string name="cancel">Annuler</string>
<string name="quit">Quitter</string>

<!-- Error message -->
<string name="no_sdcard">Aucune carte SD détéctée.
\nVeuillez obtenir une carte SD avant d\'utiliser cette application.</string>

<!-- Modes -->
<string-array name="modes">
<item>Simple</item>
<item>Aléatoire</item>
<item>Répétition</item>
</string-array>

<!-- Plurals: time_minute -->
<plurals name="time_minute">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>

</resources>
```

Much better, right?

CHANGES
=======

0.1.0 (2017-04-21)
------------------

- Initial release.

Metadata

Release files for android-strings-format 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for android-strings-format 0.1.0
File Size Uploaded Provenance
android-strings-format-0.1.0.tar.gz 2.8 kB Without provenance Details

Release files / android-strings-format-0.1.0.tar.gz

Download URL android-strings-format-0.1.0.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0d9dd3affae09d0a52b05b21d90e25ddb7cf611aebac88c0e9f54953f2cf0f8b
BLAKE2b-256 checksum
How to use checksums
be52aff26f3d3093b3ff5c7802389508cf9350a52967c14c4f59773ca3820966
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for android-strings-format 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page