Category talk:Multilingual tags: Locations

From Wikimedia Commons, the free media repository
Jump to: navigation, search

Bash script for creating location templates from wikipedia interwikis[edit]

Here's a bash script for creating location templates from wikipedia interwiki links. In short, it converts interwikis like

  • [[en:Agrinio]] to template lines as
  • |en=[[:en:Agrinio|Agrinio]] and adds the rest of the template text.

#By Badseed, distributed under the WTF Public License :P

#prompts user for input
echo "Enter name of file with interwikis:"
echo "Enter name of output file:"

#protects against forgetting to include the english interwiki
grep -q en: $INPUTFILE
if [ $return_val != 0 ] 
	echo "there's no en interwiki... please, type it in:"

#adds the template switch "header" and creates outfile
echo "{{LangSwitch

# loops reading lines from infile
while read line						
	separ=`expr index "$interwiki" :`		#finds position of separator ":" between lang ISO code and area name, not all ISOs are 2-char
	lang=${interwiki:2:separ-3}			#isolates the ISO code, by starting at index 2 and ending at separ minus 3 for [[ and :
	clean=${interwiki:2:len-4}			#strips brackets for central component
	loc=${interwiki:separ}				#rightmost location component
	new="|"$lang"=[[:"$clean"|"$loc			#constructs the final text string using previous components and |, [[, etc.
	echo  "$new">>$OUTFILE				
  done <$INPUTFILE

#prepares location's category name using the english language interwiki
engl=`grep en: $INPUTFILE`

#closes template at end and adds doc, please check the name of location's category before saving
echo "}}<noinclude>

[[Category:Multilingual tags: Locations|{{PAGENAME}}]]
[[Category:Internationalization templates using LangSwitch|{{PAGENAME}}]]

#adds documentation subpage text in the outfile, remember not to keep this part in the template page; put in the doc. subpage
echo "
|1d=<nowiki>{{$catname|xx}}</nowiki> (where xx is ISO 639-2 language code) for output in the specified language
|desc=Multilingual tag for use in the Location field of {{m|Painting}}.

:<nowiki>{{$catname}}</nowiki> - Will display the name in the language specified by user's preferences: {{$catname}}
:<nowiki>{{$catname|ru}}</nowiki> - Will always display the name in Russian: {{$catname|ru}}">>$OUTFILE

#if you're lazy like me uncomment the following to get the text directly in the terminal

How to use:

  • Copy the list of interwiki links for the location from a wikipedia (English is your best bet as they will be most complete, do not forget to add the i/w for the originating 'pedia's lang), paste to a text editor and save.
  • Run the script, you will be prompted for input & output file names, as well as for inserting the en interwiki in case you forgot (change iso code in grep ln15 for other languages)
  • After execution, the text in the output file is a complete template by the current standard and ready for pasting in the wiki. The location's category is also inserted, provided that the english article's name is the same with the category's name in Commons (please check before saving). Remember also not to save the documentation subpage text with the template but cut it and paste in the docu subpage.

As I am relatively new to bash, please don't bash my head in if the scipt looks naive to an experienced developer: it "just works" - Badseed talk 22:53, 17 January 2010 (UTC)