JavaFX 8对话框内部元素的本地化

时间:2021-03-29 17:02:41

I am currently developing a JavaFX application with Slovak language localization and inside the application I am using an Alert dialog for showing exceptions with expandable content pane as shown below on images:

我目前正在开发一个带有斯洛伐克语本地化的JavaFX应用程序,在应用程序内部,我使用Alert对话框显示可扩展内容窗格的异常,如下图所示:

JavaFX 8对话框内部元素的本地化JavaFX 8对话框内部元素的本地化

I would like to have this dialog completely translated which is going well with Header, Title or Content but I cannot find a way how to translate the Show/Hide details label of the expandable area.

我想完全翻译这个对话框,这与标题,标题或内容相符,但我找不到如何翻译可扩展区域的显示/隐藏详细信息标签的方法。

So my question can be a little bit generalized: How to change/translate text of JavaFX internal elements?

所以我的问题可以有点概括:如何更改/翻译JavaFX内部元素的文本?

Thanks in advance for any help.

在此先感谢您的帮助。

PS: For creation of this Alert dialog for exceptions I am using code as found on code.makery.ch

PS:为了为异常创建此Alert对话框,我使用的代码在code.makery.ch上找到

1 个解决方案

#1


For your particular use case, you can add another listener to expandedProperty which will override the texts shown of "details button":

对于您的特定用例,您可以向expandedProperty添加另一个侦听器,该侦听器将覆盖“详细信息按钮”所示的文本:

Platform.runLater(() ->
{
    Hyperlink detailsButton = ( Hyperlink ) alert.getDialogPane().lookup( ".details-button" );

    alert.getDialogPane().expandedProperty().addListener(
            ( ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue ) ->
    {
        detailsButton.setText( newValue ? "My less text" : "My more text" );
    });

    // trigger listeners
    alert.getDialogPane().setExpanded( true );
    alert.getDialogPane().setExpanded( false );
});

For more common hack see Localizing JavaFx Controls. From there you need to put the following keys to your custom properties file:

有关更常见的hack,请参阅本地化JavaFx控件。从那里你需要将以下键放到自定义属性文件中:

// translate these
Dialog.detail.button.more = Show Details
Dialog.detail.button.less = Hide Details

#1


For your particular use case, you can add another listener to expandedProperty which will override the texts shown of "details button":

对于您的特定用例,您可以向expandedProperty添加另一个侦听器,该侦听器将覆盖“详细信息按钮”所示的文本:

Platform.runLater(() ->
{
    Hyperlink detailsButton = ( Hyperlink ) alert.getDialogPane().lookup( ".details-button" );

    alert.getDialogPane().expandedProperty().addListener(
            ( ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue ) ->
    {
        detailsButton.setText( newValue ? "My less text" : "My more text" );
    });

    // trigger listeners
    alert.getDialogPane().setExpanded( true );
    alert.getDialogPane().setExpanded( false );
});

For more common hack see Localizing JavaFx Controls. From there you need to put the following keys to your custom properties file:

有关更常见的hack,请参阅本地化JavaFx控件。从那里你需要将以下键放到自定义属性文件中:

// translate these
Dialog.detail.button.more = Show Details
Dialog.detail.button.less = Hide Details