Alfanous-team / alfanous

Alfanous is an Arabic search engine API provides the simple and advanced search in Quran , more features and many interfaces...
http://www.alfanous.org/
GNU Affero General Public License v3.0
254 stars 89 forks source link

Add support for xx-YY language code #456

Closed sneetsher closed 7 years ago

sneetsher commented 8 years ago

Alfanous site need to handle the language code in the form of xx-YY. This is needed for OpenSearch standard used for browsers search plugin.

The current state, the site support only xx form for limited languages. Example: http://www.alfanous.org/en/?query=allah

Depending on user configuration the browser insert language parameter as xx or xx-YY. Alfanous need to work for both

Example of URL to be supported: http://www.alfanous.org/en-US/?query=Allah&page=1 http://www.alfanous.org/dd/?query=Allah&page=1

Example from Mozilla site: https://support.mozilla.org/en-US/questions/949545

The new OpenSearch template: template="http://www.alfanous.org/{language}/?query={searchTerms}&page={startPage}"

Here is the update plugin for test: https://addons.mozilla.org/en-US/firefox/addon/alfanous/

Reference:

assem-ch commented 8 years ago

Can't you limit {language} only to go through available languages:

     LANGUAGES = (
       ( 'ar', "Arabic" ),
       ( 'en', "English" ),
       ( 'fr', "French" ),
       ( 'id', "Indonesian" ),
       ( 'ja', "Japanese"),
       ( 'ku', "Kurdish" ),
       #( 'ur', "Urdu" ),
       ( 'ms', "Malay" ),
       ( 'ml', "Malayalam" ),
       #( 'tr', "Turkish" ),
       ( 'es', "Spanish" ),
       ( 'pt', "Portuguese"),
       #( 'sv', "swedish" )
     )
sneetsher commented 8 years ago

Well, I found that firefox have removed defined language tags from the plugin on installation. So pre-defining languages is not possible.

I couldn't get how firefox set the request language. Changing it from about:preferences#content languages didn't work. May be from interface or environment locales, Please , lower the priority of this issue and hold on the code change till I confirm.

sneetsher commented 8 years ago

Firefox sets the language parameter as his interface language (inherited from environment locale variables).

It will be nice if the user get alfanous results in the browser language by default.

sneetsher commented 7 years ago

@assem-ch , seems somethings wrong in Alfanous django setup. Documentation says clearly it should fall-back (ex: en-us to en) but alfanous raises 404 error.

Source: https://django.readthedocs.io/en/1.5.x/topics/i18n/translation.html

If a base language is available but the sublanguage specified is not, Django uses the base language. For example, if a user specifies de-at (Austrian German) but Django only has de available, Django uses de.

...

LANGUAGES = ( ('de', ('German')), ('en', ('English')), )

This example restricts languages that are available for automatic selection to German and English (and any sublanguage, like de-ch or en-us).

I will recheck code again see if i can figure it out.

assem-ch commented 7 years ago

@sneetsher we are using a middleware for localization because django standard does not allow languages that its core not translated yet into

sneetsher commented 7 years ago

Well, It seems Django i18n supports fall-back xx-YY to xx then to default( en in our case) but only for Accept-Language user agent header. It does not do same for URL language switch.

I has wrote one for URL but i need to test it more, so it does not break any thing