fix: improve i18n
This commit is contained in:
parent
2c4384872c
commit
da1f54f12f
4 changed files with 45 additions and 15 deletions
|
|
@ -21,6 +21,7 @@ import javafx.scene.layout.VBox;
|
||||||
import javafx.util.converter.NumberStringConverter;
|
import javafx.util.converter.NumberStringConverter;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class NutritionDetailsCtrl implements LocaleAware {
|
public class NutritionDetailsCtrl implements LocaleAware {
|
||||||
|
|
@ -57,6 +58,22 @@ public class NutritionDetailsCtrl implements LocaleAware {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Callable<String> getEstimatedKcalLabel() {
|
||||||
|
IngredientViewModel vm = this.ingredient.get();
|
||||||
|
return () -> String.format(getLocaleString("app.kcal") + " %.1f kcal/100g", vm.getKcal());
|
||||||
|
}
|
||||||
|
|
||||||
|
Callable<String> getUsageLabel() {
|
||||||
|
IngredientViewModel vm = this.ingredient.get();
|
||||||
|
return () -> {
|
||||||
|
Long id = this.ingredient.get().toIngredient().getId();
|
||||||
|
logger.info("Fetching usage for ingredient ID: " + id);
|
||||||
|
return !id.equals(0L) ? String.format(
|
||||||
|
getLocaleString("app.label.usage.part") + " %d " + getLocaleString("app.word.recipe.n"),
|
||||||
|
server.getIngredientUsage(id)) : "";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initializeComponents() {
|
public void initializeComponents() {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
|
|
@ -65,19 +82,8 @@ public class NutritionDetailsCtrl implements LocaleAware {
|
||||||
this.fatInputElement.textProperty().bindBidirectional(vm.fatProperty(), new NumberStringConverter());
|
this.fatInputElement.textProperty().bindBidirectional(vm.fatProperty(), new NumberStringConverter());
|
||||||
this.proteinInputElement.textProperty().bindBidirectional(vm.proteinProperty(), new NumberStringConverter());
|
this.proteinInputElement.textProperty().bindBidirectional(vm.proteinProperty(), new NumberStringConverter());
|
||||||
this.carbInputElement.textProperty().bindBidirectional(vm.carbsProperty(), new NumberStringConverter());
|
this.carbInputElement.textProperty().bindBidirectional(vm.carbsProperty(), new NumberStringConverter());
|
||||||
this.estimatedKcalLabel.textProperty().bind(Bindings.createStringBinding(
|
this.estimatedKcalLabel.textProperty().bind(Bindings.createStringBinding(this.getEstimatedKcalLabel(), vm.kcalProperty()));
|
||||||
() -> String.format(getLocaleString("app.kcal") + " %.1f kcal/100g", vm.getKcal()), vm.kcalProperty()
|
this.usageLabel.textProperty().bind(Bindings.createStringBinding(this.getUsageLabel(), this.ingredient.get().idProperty()));
|
||||||
));
|
|
||||||
this.usageLabel.textProperty().bind(Bindings.createStringBinding(
|
|
||||||
() -> {
|
|
||||||
Long id = this.ingredient.get().toIngredient().getId();
|
|
||||||
logger.info("Fetching usage for ingredient ID: " + id);
|
|
||||||
return !id.equals(0L) ? String.format(
|
|
||||||
getLocaleString("app.label.usage.part") + " %d " + getLocaleString("app.word.recipe.n"),
|
|
||||||
server.getIngredientUsage(id)) : "";
|
|
||||||
},
|
|
||||||
this.ingredient.get().idProperty()
|
|
||||||
));
|
|
||||||
});
|
});
|
||||||
this.nutritionValueContainer.addEventHandler(KeyEvent.KEY_RELEASED, event -> {
|
this.nutritionValueContainer.addEventHandler(KeyEvent.KEY_RELEASED, event -> {
|
||||||
if (event.getCode() != KeyCode.ENTER) {
|
if (event.getCode() != KeyCode.ENTER) {
|
||||||
|
|
@ -101,7 +107,15 @@ public class NutritionDetailsCtrl implements LocaleAware {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateText() {
|
public void updateText() {
|
||||||
|
try {
|
||||||
|
this.estimatedKcalLabel.textProperty().setValue(this.getEstimatedKcalLabel().call());
|
||||||
|
this.usageLabel.textProperty().setValue(this.getUsageLabel().call());
|
||||||
|
this.fatInputLabel.setText(this.getLocaleString("menu.nutrition.fat"));
|
||||||
|
this.proteinInputLabel.setText(this.getLocaleString("menu.nutrition.protein"));
|
||||||
|
this.carbInputLabel.setText(this.getLocaleString("menu.nutrition.carbs"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVisible(boolean isVisible) {
|
public void setVisible(boolean isVisible) {
|
||||||
|
|
@ -134,6 +148,7 @@ public class NutritionDetailsCtrl implements LocaleAware {
|
||||||
public LocaleManager getLocaleManager() {
|
public LocaleManager getLocaleManager() {
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleNutritionSaveClick(ActionEvent actionEvent) throws IOException, InterruptedException {
|
public void handleNutritionSaveClick(ActionEvent actionEvent) throws IOException, InterruptedException {
|
||||||
Ingredient newIngredient = updateIngredient();
|
Ingredient newIngredient = updateIngredient();
|
||||||
this.ingredient.get().updateFrom(server.updateIngredient(newIngredient));
|
this.ingredient.get().updateFrom(server.updateIngredient(newIngredient));
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,14 @@
|
||||||
package client.scenes.nutrition;
|
package client.scenes.nutrition;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
|
||||||
public class NutritionViewCtrl {
|
public class NutritionViewCtrl {
|
||||||
@Inject
|
@Inject
|
||||||
public NutritionViewCtrl(
|
public NutritionViewCtrl(
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
NutritionDetailsCtrl nutritionDetailsController;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -411,6 +411,17 @@ public class RecipeDetailCtrl implements LocaleAware {
|
||||||
addToListButton.setText(getLocaleString("app.word.shop"));
|
addToListButton.setText(getLocaleString("app.word.shop"));
|
||||||
scaleLabel.setText(getLocaleString("app.word.scale"));
|
scaleLabel.setText(getLocaleString("app.word.scale"));
|
||||||
servingLabel.setText(getLocaleString("app.word.serving.n"));
|
servingLabel.setText(getLocaleString("app.word.serving.n"));
|
||||||
|
|
||||||
|
if (this.recipeView != null && this.recipeView.getRecipe() != null) {
|
||||||
|
inferredKcalLabel.textProperty().bind(Bindings.createStringBinding(() ->
|
||||||
|
String.format(getLocaleString("app.label.inferred-kcal") + " %.1f kcal/100g",
|
||||||
|
Double.isNaN(this.recipeView.scaledKcalProperty().get()) ?
|
||||||
|
0.0 : this.recipeView.scaledKcalProperty().get())
|
||||||
|
, this.recipeView.scaledKcalProperty()));
|
||||||
|
inferredServeSizeLabel.textProperty().bind(Bindings.createStringBinding(
|
||||||
|
() -> String.format(getLocaleString("app.label.inferred-size") + " %.1f g", recipeView.servingSizeProperty().get()),
|
||||||
|
recipeView.servingSizeProperty()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,6 @@
|
||||||
prefHeight="400.0" prefWidth="600.0">
|
prefHeight="400.0" prefWidth="600.0">
|
||||||
<SplitPane>
|
<SplitPane>
|
||||||
<fx:include source="IngredientList.fxml" />
|
<fx:include source="IngredientList.fxml" />
|
||||||
<fx:include source="NutritionDetails.fxml" />
|
<fx:include fx:id="nutritionDetails" source="NutritionDetails.fxml" />
|
||||||
</SplitPane>
|
</SplitPane>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue