you can find an example in the rails guides: http://guides.rubyonrails.org/i18n.html#setting-the-locale-from-the-domain-name
its about domain names, but you can adapt it to your needs pretty easily.
keep in mind that subdomains introduce a lot of complexity into your app. cookies, javascript and ssl are sensitive to domains. make sure, that it's worth using subdomains vs. paths.