Skip to content

Instantly share code, notes, and snippets.

@ngs
Created April 15, 2011 22:25
Show Gist options
  • Save ngs/922577 to your computer and use it in GitHub Desktop.
Save ngs/922577 to your computer and use it in GitHub Desktop.
Let teammates localize my app with Google Spreadsheets

#Let teammates localize my app with Google Spreadsheets

###In your terminal

$ ppit set docs.google.com

###Then $EDITOR launches. Edit the content like below. // be sure use your actual account

----
username: [email protected]
password: Pa55w0Rd!$

###Put the script in your Xcode project directory structure the below.

  • GetLocalizableStringsFromSS.pl
  • MyProject.xcodeproj
  • Resources/
    • Localizations/
      • English.lproj/
        • Localizable.strings
      • Japansese.lproj/
        • Localizable.strings
      • Simplified Chinese.lproj/
        • Localizable.strings
      • ...
  • Classes/
  • ...

###Create Spreadsheet

Key Englsih Japansese Simplified Chinese
Hello こんにちは 你好
SomeLongText Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Aenean sagittis mi sed ipsum eleifend commodo.
これは平生ひょろひょろその所有方というものの時を読んないでし。
すでに絶対を話通りはようやくある講演たべからばかりをなりて得るませをも病気なっませですば、なぜにはしですないありあり。
头 指人 世界上大约有 使用人数约为, 使用人数约为 客家话因而保留了些中古北方话的特点
吗 同时, 中国国家标准的简称 使用人数大约为总人口的 这与欧洲语言的情况不同 体 徽语 另外 及

If Key field is empty, English field will be used as key instead.

#!/usr/bin/env perl -w
use strict;
use warnings;
use constant SHEET_TITLE => 'my_team_sheet';
use constant WORKSHEET_TITLE => 'LocalizableStrings';
use Config::Pit;
use Data::Dumper;
use Encode;
use FindBin;
use Net::Google::Spreadsheets;
use String::CamelCase qw/camelize/;
use Symbol;
my $config = pit_get("docs.google.com");
my $service = Net::Google::Spreadsheets->new(%$config)
or die "You must specify username and password\n ppit set docs.google.com";
my $ss = $service->spreadsheet({ title => SHEET_TITLE });
my $ws = $ss->worksheet({ title => WORKSHEET_TITLE });
my @rows = $ws->rows;
my $strings = {};
foreach( @rows ) {
my $content = $_->content;
my $key = $content->{key} || $content->{english};
foreach( keys %$content ) {
next if $_ =~ /^(_.*|key)$/;
$strings->{$_} ||= '';
( my $text = $content->{$_} || '' ) =~ s/\n/\\n/g;
$text =~ s/"/\\"/g;
$strings->{$_} .= qq{"$key" = "$text";\n} if $text;
}
}
foreach( keys %$strings ) {
my $fh = Symbol::gensym();
my $locale = camelize $_;
my $out = $strings->{$_};
$out =<<EOM;
/*
Localizable.strings
Auto generated by GetLocalizableStringsFromSS.pl
*/
$out
EOM
open $fh, ">$FindBin::RealBin/Resources/Localizations/$locale.lproj/Localizable.strings";
print $fh encode( 'utf-8', $out );
close $fh;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment