Convert days and months in french for an axis of type DateTimeRuler

6 views (last 30 days)
Hello,
I try to change language/locale for labels of axis of type DateTimeRuler with set(0,'Language',"fr_FR") without success ! Is ther another solution ?

Accepted Answer

Shivam Gothi
Shivam Gothi on 23 Nov 2024
As per my understanding, you are trying to show the labels of axis containing "datetime" data in "French" language. There is no direct way to achieve the objective, but I found few workarounds which may help to resolve your question.
1) You can change the output dates to any user-preferred Locale
use Locale option from preferences (Preferences -> Command Window -> Datetime format -> Locale). If you can not see a particular Locale in a drop down menu, just type in there and apply the changes. It will accept it if you type in correctly. For example, if you want the output to be displayed in French, type the Locale as "fr_FR" and apply the changes. You will observe the output from "datetime" function displayed in German
2) You can use "cellstr" function to specify the "locale" property as demonstrated below:
%C = cellstr(D,'fmt',"fr_FR") %fmt = output format of datetime object (D)
Refer to the documentation to find more information about the function:
I have also illustrated its use by a small example as shown below:
%create an array of datetime object for demonstration purpose
year=2024+ones(1,6);
month= [1 2 3 4 5 6];
day=13+ones (1,6);
datearr =datetime(year, month, day)
datearr = 1x6 datetime array
14-Jan-2025 14-Feb-2025 14-Mar-2025 14-Apr-2025 14-May-2025 14-Jun-2025
C=cellstr(datearr,'MMM d, yyyy',"fr_FR") %you can specify any datetime format "fmt". Here, it is 'MMM d, yyyy'
C = 1x6 cell array
{'janv 14, 2025'} {'févr 14, 2025'} {'mars 14, 2025'} {'avr 14, 2025'} {'mai 14, 2025'} {'juin 14, 2025'}
%create data for y-axis (for demonstration)
y_data=[1 2 3 4 5 6];
A=plot(datearr,y_data);
A.Parent.XTickLabel=C;
As seen, the xlabels are now appearing in French language. I hope this answers your question !
  2 Comments
Laurent Fritz
Laurent Fritz on 23 Nov 2024
Thanks a lot, the first solution is best for my needs in order to be able to continue zooming xaxis.
Shivam Gothi
Shivam Gothi on 24 Nov 2024
Thankyou for the reply. You can find the "preferences" tab as shown in the below figure.
Set the "Locale" property to "fr-FR" by manually typing it and then clicking "apply". It will only change the Locale of "datetime" object. Not the entire Command window.
I tried this and found to be working.
Moreover, if you find any of the responses helpful and they resolve the issue you're facing, it would be wonderful if you could mark the answer as "accepted". This will assist the community users in finding more precise and accurate solutions.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!