At 15:42 -0700 01/09/2011, jamie wrote:
Thanks for the responses. Yes exactly. Just swapping out a language 2
letter ISO code and saving new TXT documents with that ISO code in the
filename. I usually have 30 - 50 instances of the 2 letter code in my
TXT documents.
For example:
Text file "MYTEXT_EN.TXT" has:
path:EN.tif change to path:(variable).tif
(variable) is pulled from a list of 35 languages from another file. Such as
KR,
GB,
AU,
etc.
Save out 35 files with MYTEXT_(variable-language).TXT
Is this possible w/ BBedit? I've just picked up some Perl books at B&N
but I'd love to use BBEdit.
BBEdit does it's cleverest stuff by using Apple events and shell
scripts -- Perl etc. You could use Perl alone but in this case you
might like to use a combination of AppleScript and Perl.
If you paste this script into Script Editor and run it with your
template file frontmost in BBEdit, the script will find all instances
of "_EN." (case-sensitive), create a file substituting the country
code for EN both in the file name and in its contents. The search
pattern I have used may not be exactly what you need.
The script can be saved in your BBEdit Scripts folder and run from
the palette or with a key shortcut. You could keep the country codes
in a separate file and have the script read that but I don't see the
point.
tell application "BBEdit"
tell front document
save it
set _template_mac to its file
end tell
set _template to POSIX path of _template_mac
end tell
do shell script "perl <<\"END\"
my @country_codes = qw(FR DE GB CN
BR KR SE NO TH CL GR);
my $template = qq~" & _template & "~;
open my $file_handle, qq~<$template~ or die $!;
my @lines = <$file_handle>; # Get the contents of the template
close $file_handle;
print qq~TEMPLATE: $template\\n\\n~; # just for demo
foreach my $cc (@country_codes){
$_ = $template;
s~(_)(EN)(\\.)~$1$cc$3~;
my $new_file = $_; # Create a new file name
print qq~$new_file\\n~; # just for demo
open FH, qq~>$new_file~ or die $!;
foreach (@lines){
s~(_)(EN)(\\.)~$1$cc$3~;
print FH;
}
close FH
}
END
"
--end of script
--
You received this message because you are subscribed to the
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem,
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>