Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Localize objc M files

Project Description

localize_m: Easy localization of objc .m files

Localize_m helps with localizing your objc .m files. It has two modes:

  1. Interactively parse your file, and ask for each string whether it should be localized ( --ask-all option).
  2. Automatically parse your file and replace each @"..." string prefixed with __LOCALIZE with a localized version. This mode can run in a fully automated fashion or, when you use the -c option, localize_m will ask you to edit the slug and to provide a comment for the translator.

localize_m inserts the following code for each @"..." string you choose to replace:

NSLocalizedStringWithDefaultValue(<slug>, kDefaultLocalizationTable, kClassBundle, @"...", @"...")

We use this function instead of NSLocalizedString, as it gives full flexibilty, and provides comments to the translator. In fact, we do not recommend using NSLocalizedString.

Slugs and Localization ID’s

Localize_m automatically generates slugs from your strings to act as identifiers for your translations. Formatting codes %@, %d, etc are replaced by [] in your slugs, for ease of reading. Why do we use slugs as id?

  1. slugs should uniquely describe the string. Even if you have the same @”Example” string at multiple place in your code, you may want to be able to translate to Dutch with @”Voorbeeld”, and with @”Bijv.” at another place. So if you use slugs example-long-form and example-short-form, you can discriminiate between the two
  2. To help you resist the temptation to edit the ID. Never edit the ID, when your strings have been translated.


In your project.pch precompiled header define:

#define __LOCALIZE
#define kClassBundle [NSBundle bundleForClass:[self class]]
#define kDefaultLocalizationsTable nil

This makes sure that your project compiles, even when you have put __LOCALIZEs in your code, and haven’t run the localize_m script yet. We use [NSBundle bundleForClass:[self class]] so that your project is framework compatible. You can manually override the kDefaultLocalizationsTable with a string, when you want to use another table than the default Localizations.strings file.


localize_m [-h] [-p PATH] [-o [outfile]] [-a] [-c] [--inplace]
           [--table TABLE] [--bundle BUNDLE] [--replace REPLACE]

  -p PATH, --path PATH  localize all .m files in path
  infile                Input .m file
  -o [outfile], --outfile [outfile]
                        Output file, otherwise stdout
  -a, --ask-all         ask for all strings (interactive))
  -c, --comments        ask for comments and ids (interactive)
  --inplace             localize file in-place

  --table TABLE         custom localizations table argument
  --bundle BUNDLE       custom NSBundle argument
  --replace REPLACE     Auto localization prefix string


Localize_m uses python, which is installed on every Mac by default. Use pip to install:

# pip install localize_m
Collecting localize-m
  Downloading Localize_M-1.0.tar.gz
Collecting colored (from localize-m)
  Using cached colored-1.2.1.tar.gz
Collecting slugify (from localize-m)
  Using cached slugify-0.0.1.tar.gz
Collecting gnureadline (from localize-m)
  Using cached gnureadline-6.3.3-cp27-none-macosx_10_6_intel.whl
Installing collected packages: colored, slugify, gnureadline, localize-m
  Running install for colored
  Running install for slugify
  Running install for localize-m
Successfully installed colored-1.2.1 gnureadline-6.3.3 localize-m-1.0 slugify-0.0.1



One file

# cd project/src
# localize_m MainViewController.m --comments --inplace

All m files

localize_m -p ./ --comments

You can go through all files. Press CTRL-C to save your changes and quit. Just start localize_m again to resume where you left.


# localize_m MainViewController.m --table '@"MyTable"' --bundle '[NSBundle mainBundle]'

Uses the @"MyTable" string as the localizationsTable argument and [NSBundle mainBundle] as the bundle argument for NSLocalizedStringWithDefualtFormat funtion.

Release History

Release History

This version
History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
Localize_M-1.0.1.tar.gz (5.5 kB) Copy SHA256 Checksum SHA256 Source Oct 7, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting