Wednesday, July 31, 2013

RTL Bootstrap CSS Convertor

Bootstrap.css is great, Bootstrap.css 3 is better. Alas, Neither have an RTL version. There are a couple of not-maintained gits floating around the web for bootstrap 2 but non for bootstrap 3

To convert bootstrap 3 to RTL you can use https://github.com/ded/R2

but be aware that there is currently a pending issue with media queries not being converted properly.

If you can't wait for this to be resolved by the maintainer you can manually patch the rs.2js based on my branch at https://github.com/ded/R2/pull/23/files

Note that this is not thoroughly tested and will probably not be maintained if I won't have time to maintain it.

EDIT: The above issue is now merged into the R2 master and also have been tested quite well.

If you want a rather stable, working, version of RTL bootstrap.css you can use the one from my repository at https://bitbucket.org/levynir/bootstrap3-rtl. Even if you decide to brew your own version, I recommend that you read the README on this bitbucket as there are some caveats to RTLing bootstrap.

Tuesday, July 30, 2013

Setting I18N Hebrew in Django 1.5

It should be simple. But the docs are not very clear. So here is how to setup you Django site to be in Hebrew (or any other language).

The need: Make my site work in Hebrew, without taking into account Browser's Accept Language and all this stuff.

Ingredients: Working Django 1.5 project on Linux, common sense

Steps:


Install GNU gettext (even if you think you have it already)

sudo apt-get install gettext
Change in projectname/settings.py

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
# LANGUAGE_CODE = 'en-us'
# This will force this installation to be in Hebrew
LANGUAGE_CODE = 'he'

#...

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
Make sure your MIDDLEWARE_CLASSES do not have LocaleMiddleware. If you do have LocaleMiddleware than Django will try to guess the right locale from the request context, which we don't want at the moment.

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    #Comment out LocaleMiddleware if it's there to keep in the same locale all the time
    #'django.middleware.locale.LocaleMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
You may also need to add django.core.context_processors.i18n to your TEMPLATE_CONTEXT_PROCESSORS. (Don't do that right now, wait and see if everything is working and only add this if stuff is not working)

#add this at the end of settings.py if I18N is not working
from django.conf import global_settings
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
    ".context_processors.site",
    "django.core.context_processors.i18n",
)
In your python code wrap translatable texts with ugettext_lazy or ugettext (you can and should alias them to some conventional shortcut (I use _t for ugettext and _ for ugettext_lazy, for example

from django.utils.translation import ugettext_lazy  as _
from django.utils.translation import ugettext  as _t
class Shirt(models.Model):
    COLOR_TYPES = (
                    ('B', _('Blue')),
                    ('G', _('Green')),
                    )
    
    ...
    color = models.CharField(max_length=1, choices=COLOR_TYPES)
    type(self):
        return _t('Shirt')

In your templates you need to use this (ugly and hard to read) method

{% load i18n %}
<!-- Make sure this LANGUAGE_CODE is correct: {{LANGUAGE_CODE}} -->
...
<h1>{%trans "Shirt Store"%}</h1>
...
or you can use {{_("Shirt Store")}} as an alternative method
Remember that you need to {% load i18n %} in every template that uses {%trans%}.

Now we need to create the tranlsation files themselves:


cd django-project
cd django-app
mkdir locale
django-admin.py makemessages -l he
vi locale/he/LC_MESSAGES/django.po
django-admin.py compilemessages
Rinse, repeat

Run your site and hope for the best.

Sources:

Thursday, August 23, 2012

"Type 'Newtonsoft.Json.Linq.JToken' is a recursive collection data contract" While Adding Service Reference in VS2012

Trying to add a service reference in Visual Studio 2012 to Bing Maps SOAP service I got the following error message:


Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Type 'Newtonsoft.Json.Linq.JToken' is a recursive collection data contract
...

Following Getting “Recursive collection data contract” when referencing a WCF service with a slightly complex method and Visual Studio 2012 Error Reference.svcmap throwing Error I've had to change the "reuse types in referenced assemblies" from "all" to everything except Newtonsoft.JSON and RestSharp.

Might not be something to write home about, but I'm sure I'll forget where it is was in a year or so.

PS. This seems to be VS2012 only issue, VS2010 worked just fine.

Thursday, November 18, 2010

Tech-Ed Eilat 2010

So happy to be presenting at Tech-Ed Eilat 2010.
See you all at the Herods Hotel, Tue 30/11 at 11:15 where we would share our lessons from the field on enterprise web content management with SharePoint 2010.

You can read more about our session at the realcommerce web site.

Tuesday, January 26, 2010

IIS JNLP 404 Problem

If your IIS 6 returns a 404 Not Found when you request a Java Web Start jnlp file, then you probably need to add the jnlp mime-type to the IIS configuration.

IIS Settings -> Right click the machine -> mime-types -> new Extension: .jnlp MIME Type: application/x-java-jnlp-file


Sunday, October 4, 2009

How to do rewrites in an IIS ISAPI

Note to self: If ever you need to do a rewrite in an IIS ISAPI Filter you just need to re-set the pHeaderInfo's url header. Something like this:

 
pHeaderInfo->GetHeader(pCtxt->m_pFC,
"url",strUrl.GetBuffer(dwUrlSize+1),&dwUrlSize);
strUrl.ReleaseBuffer();
strNewUrl = GET_REWRITE_FOR_URL(strUrl);
if ( strNewUrl.IsEmpty() == FALSE ) {
pHeaderInfo->SetHeader(pCtxt->m_pFC,
"url", (LPTSTR)(LPCTSTR)strNewUrl);
}
return SF_STATUS_REQ_NEXT_NOTIFICATION;

This is working in IIS4 and above.

Note that if you really need a good re-write/redirect filter for IIS you should look at IIRF ,but since it's not working for IIS4 i had to do this manually

Thursday, June 18, 2009

Bing, Google, Nutch and Canonical URLs

Google announced a few months back that they started supporting canonical urls. This is a great feature that we already adopted in a couple of sites (mostly to keep tracking codes from messing with our search engine results.

Unfortunelty, altough Microsoft announced they will support this feature in Live, this was not yet implemented in Bing as of now (Jun 2009).

Nutch, on the other hand, had this on thier TODO list for 1.1.

Also, Google Search Appliance (GSA), is currently assumed by all to not support this (although nobody really knows if it does).

More about canonical URLs:
http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html
http://searchengineland.com/canonical-tag-16537
http://janeandrobot.com/library/url-referrer-tracking