# Language\_redirect

**URL:** <https://www.ruby-forum.com/t/language-redirect/108161>\
**Category:** Radiant CMS\
**Created:** [June 29, 2007, 3:12pm UTC](https://www.ruby-forum.com/t/language-redirect/108161 "2007-06-29T15:12:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Keymone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8dc957/32.png) [@Keymone](https://www.ruby-forum.com/u/Keymone)\
**Post date:** [June 29, 2007, 3:12pm UTC](https://www.ruby-forum.com/t/language-redirect/108161/1 "2007-06-29T15:12:29Z")

</div>

Hello!

did somebody noticed that language\_redirect does not handle windows line  
endings?  
it redirects me to something like /uk/%0D instead of just /uk/

i tried to fix it myself but this:

q = lambda { |str| /;q=/ =~ str ? Float($’) : 1 }  
langs = langs.collect do |ele|  
[q.call(ele), ele.split(/;/)[0].downcase]  
end.sort { |l, r| r[0] \<=\> l[0] }.collect { |ele| ele[1] }

is strangest code i’ve ever seen in my life 😃  
isn’t ruby supposed to be easy-readable? 😉

---

<div class="post-metadata">

**Author:** ![Keymone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8dc957/32.png) [@Keymone](https://www.ruby-forum.com/u/Keymone)\
**Post date:** [June 29, 2007, 3:28pm UTC](https://www.ruby-forum.com/t/language-redirect/108161/2 "2007-06-29T15:28:32Z")

</div>

That code is quite interesting actually. John did you write it?

The first line (q= …) defines a lambda, that is a proc, that is a  
method that can be assigned to a variable.

It’s equal to

def q(str)  
if str.match(/;q=/)  
$’.to\_f # $’ returns the string that follows the matched part  
else  
1  
end  
end

The second line uses Array#collect to build an array of size-two  
arrays. Each one has the result of q as first element and the language  
code as second element.

The last part sorts this array by priority (which is the result of q)  
and then collects only the language names.

The final result then is an array of languages ordered by priority.

---

<div class="post-metadata">

**Author:** ![Keymone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8dc957/32.png) [@Keymone](https://www.ruby-forum.com/u/Keymone)\
**Post date:** [June 29, 2007, 3:31pm UTC](https://www.ruby-forum.com/t/language-redirect/108161/3 "2007-06-29T15:31:32Z")

</div>

thanks 🙂  
anyway problem is few lines upper:

— app/models/language\_redirect\_page.rb (revision 3)  
+++ app/models/language\_redirect\_page.rb (working copy)  
@@ -18,7 +18,9 @@

protected  
def config

- 

```
 Hash[*render_part(:config).split(/[\n:]/)]

```

- 

```
 rules = render_part(:config)

```

- 

```
 rules[/\r\n/] = "\n"

```

- 

```
 Hash[*rules.split(/[\n:]/)]

```

end

def languages

this fixes problem for me

if somebody can - commit this to repository

thanks 🙂
