%% Changes
% See line 54, where I added `captiondirection` key
% The following redefinition is not needed and I have deleted it:
% \def\lstlistingname{برنامه}
% See also line 81, `caption' no longer needs \rl
\documentclass[openany, 12pt]{book} 

\usepackage{color}
\usepackage{xcolor} 
\usepackage{listings}
\usepackage{xepersian}


%---listings colors 
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
%---listings colors 
 
\lstdefinestyle{mystyle}{
	tabsize=4,
	breaklines=true,
	breakatwhitespace=true,
	basicstyle=\footnotesize\ttfamily,
	numberstyle=\footnotesize\ttfamily,
	aboveskip=\baselineskip,
	captionpos=b,
	columns=fullflexible,
	showstringspaces=false,
	extendedchars=true,
	breaklines=true,
	showtabs=false,
	showspaces=false,
	showstringspaces=false,
	identifierstyle=\ttfamily,
    backgroundcolor=\color{backcolour},   
    commentstyle=\scriptsize\ttfamily,
    numberstyle=\tiny\color{codegray},
    stringstyle=\bfseries\ttfamily,
    basicstyle=\LSTfont,
    breakatwhitespace=false,         
    breaklines=true,                 
    captionpos=b,                    
    keepspaces=true,                 
    numbers=none,                    
    numbersep=5pt,                  
    showspaces=false,                
    showstringspaces=false,
    showtabs=false,                  
    tabsize=2,
    escapechar=|,
    %frame=trBL
    basicstyle=\footnotesize\ttfamily,
	keywordstyle=\bfseries\ttfamily,
	captiondirection=RTL % this requires v14.1 of xepersian and v15.1 of bidi package
}

\setlatinmonofont[ExternalLocation,BoldFont={cmuntb},ItalicFont={cmunti},BoldItalicFont={cmuntx}]{cmuntt} 
\setlatinmonofont[ExternalLocation,BoldFont={pcrb8a},ItalicFont={pcri8a},BoldItalicFont={pcrbi8a}]{pcrr8a}

\lstset{style=mystyle}





\setdigitfont[Scale=1.1]{ParsiDigits}
\settextfont[Scale=1.2]{XB Yas}
\defpersianfont\nastaliq[Scale=1.6]{IranNastaliq}
\defpersianfont\persiantitle[Scale=1.6]{XB Yas}
\defpersianfont\authername[Scale=1.3]{XB Yas}


\begin{document}

چطور میشه عنوان رو درست کرد. یعنی الان عنوان باید باشه 

برنامه 1: کد جاوا

\begin{LTR}
\lstset{language=JAVA, inputencoding={utf8}}
\begin{lstlisting}[texcl,caption={کد جاوا}]
some code...
\end{lstlisting}
\end{LTR}



\end{document} 