I have come across a very peculiar problem. The sections and subsections show correctly in my output when the language is set to English. But when I change the language to Hebrew which it needs to be to display the RTL language correctly, the sections and subsections are messed up. I need to understand why this is happening and how to fix it, please.
The only change between the two examples is \setmainlanguage{english} changed to \setmainlanguage{hebrew}.
An ideal answer would use the hebrewnumerals feature, but show only the relevant subsection and section parts of the number. As in 2 instead of 1.1.2 or rather ב instead of א.א.ב
Example 1:

Example 2:

MWE: (compile it in XeLaTeX with Cardo font)
\documentclass[paper=a5,pagesize=pdftex]{scrbook}
\usepackage[top=2cm,bottom=1.5cm, left=1.5cm, right=1.5cm]{geometry}
\usepackage[pagestyles]{titlesec}
\usepackage{lettrine}
\usepackage{xltxtra}
\usepackage{tocloft}
\usepackage{etoolbox}
\usepackage[toc]{multitoc}
\usepackage{setspace}
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{\arabic{subsection}}
\setcounter{tocdepth}{0}
\setcounter{secnumdepth}{2}
\defaultfontfeatures{Mapping=tex-text}
\setmainfont{Cardo}
% sets the marks to be used (section and subsection)
\setmarks{section}{subsection}
\newlength\howwide
\newcommand\defhowwide{
\ifnumless{\value{section}}{99}{\ifnumgreater{\value{section}}{8}{\setlength{\howwide}{2.5em}}{\setlength{\howwide}{1.2em}}}{\ifnumgreater{\value{section}}{98}{\setlength{\howwide}{3.5em}}{\setlength{\howwide}{2.5em}}}
}
% sections and subsections formatting
\titleformat{\section}{}{\lettrine{\thesection}}{0em}{}[\vskip-1\baselineskip]
\titleformat{\subsection}[runin]{\small\bfseries}{\thesubsection}{1em}{}
\titlespacing{\section}{\howwide}{-1pt}{0pt}
\titlespacing{\subsection}{0pt}{0pt}{1em}
\setlength{\parindent}{0pt}
\newlength\NumLen
\newlength\LinLen
% indents one line of text. Indentation= width of section number + 1em
\newcommand\IndOne{%
\setlength\NumLen{\howwide}
\addtolength\NumLen{0.5em}
\setlength\LinLen{\dimexpr\textwidth-\NumLen}%\the\NumLen\the\LinLen
\parshape 2 \NumLen \LinLen 0pt \textwidth}
% indents two lines of text. Indentation= width of section number + 1em
\newcommand\IndTwo{%
\setlength\NumLen{\howwide}
\addtolength\NumLen{0.5em}
\setlength\LinLen{\dimexpr\textwidth-\NumLen}%\the\NumLen\the\LinLen
\parshape 3 \NumLen \LinLen \NumLen \LinLen 0pt \textwidth}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{english}
\begin{document}
\mainmatter
\newlength{\myIndent}
\setcounter{section}{0}
\addtocounter{chapter}{1}
\setcounter{section}{0}
\defhowwide
\section{}
\settowidth{\myIndent}
{\IndOne בְּרֵאשִׁית בָּרָא אֱלֹהִים אֵת הַשָּׁמַיִם וְאֵת הָאָרֶץ׃}
\ifdimless{\the\myIndent}
{\textwidth-\howwide+0.75em}
{\IndOne בְּרֵאשִׁית בָּרָא אֱלֹהִים אֵת הַשָּׁמַיִם וְאֵת הָאָרֶץ׃ \stepcounter{subsection}
\subsection{} \IndOne וְהָאָרֶץ הָיְתָה תֹהוּ וָבֹהוּ וְחֹשֶׁךְ עַל־פְּנֵי תְהֹום וְרוּחַ אֱלֹהִים מְרַחֶפֶת עַל־פְּנֵי הַמָּיִם׃}
{\IndTwo בְּרֵאשִׁית בָּרָא אֱלֹהִים אֵת הַשָּׁמַיִם וְאֵת הָאָרֶץ׃ \stepcounter{subsection} \subsection{} וְהָאָרֶץ הָיְתָה תֹהוּ וָבֹהוּ וְחֹשֶׁךְ עַל־פְּנֵי תְהֹום וְרוּחַ אֱלֹהִים מְרַחֶפֶת עַל־פְּנֵי הַמָּיִם׃}
\subsection{} וַיֹּאמֶר אֱלֹהִים יְהִי אֹור וַיְהִי־אֹור׃
\end{document}
polyglossiaand setting the languages. – Alan Munn Mar 12 '12 at 15:21