GUI - switching language

조회 수: 3 (최근 30일)
keenN
keenN 2011년 2월 22일
답변: Roberto 2014년 4월 26일
Hello, I am working on a GUI with a language selection. I put the language selection in a listbox as strings. My question is, how do I program the GUI to be able to change all the texts in current GUI and all other connected GUIs according to the language selected? I'd really appreciate anyone's help. Thanks!

답변 (1개)

Roberto
Roberto 2014년 4월 26일
you'll have to store all the 'strings' in a external file, or in the same file but it's going to be huge: here's an idea of how to do it, as simple as 1,2,3:
1. Create a GUI with default text values and tag properties considering previous tags:
f= figure ;
h1 = uicontrol(f,'style','pushbutton','position',[10 10 200 20],...
'tag','txtOne','String','default text') ;
h2 = uicontrol(f,'style','text','position',[10 35 200 20],...
'tag','txtother','String','default text2') ;
2. Create a function to change the 'String' property for all elements
function changeLan(figureHandle,lanIndex)
tags = {'txtOne','txtother'} ;
strs{1} = {'My text', 'Other text'} ;
strs{2} = {'Mi texto', 'otro texto'} ;
for i = 1:length(tags)
handle = findobj(f,'tag',tags{i}) ;
set(handle,'String',strs{lanIndex}{i});
end
end
3. call the function to change the language:
changeLan(f,1);
changeLan(f,2);
Hope it will help you! :)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by