Merge branch 'fix/even-better-i18n' into 'main'

Fix: improve i18n and finish up the last untranslated text

See merge request cse1105/2025-2026/teams/csep-team-76!96
This commit is contained in:
Natalia Cholewa 2026-01-24 14:30:33 +01:00
commit a32f4cd781
4 changed files with 45 additions and 15 deletions

View file

@ -21,6 +21,7 @@ import javafx.scene.layout.VBox;
import javafx.util.converter.NumberStringConverter;
import java.io.IOException;
import java.util.concurrent.Callable;
import java.util.logging.Logger;
public class NutritionDetailsCtrl implements LocaleAware {
@ -57,6 +58,22 @@ public class NutritionDetailsCtrl implements LocaleAware {
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
public void initializeComponents() {
Platform.runLater(() -> {
@ -65,19 +82,8 @@ public class NutritionDetailsCtrl implements LocaleAware {
this.fatInputElement.textProperty().bindBidirectional(vm.fatProperty(), new NumberStringConverter());
this.proteinInputElement.textProperty().bindBidirectional(vm.proteinProperty(), new NumberStringConverter());
this.carbInputElement.textProperty().bindBidirectional(vm.carbsProperty(), new NumberStringConverter());
this.estimatedKcalLabel.textProperty().bind(Bindings.createStringBinding(
() -> String.format(getLocaleString("app.kcal") + " %.1f kcal/100g", vm.getKcal()), vm.kcalProperty()
));
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.estimatedKcalLabel.textProperty().bind(Bindings.createStringBinding(this.getEstimatedKcalLabel(), vm.kcalProperty()));
this.usageLabel.textProperty().bind(Bindings.createStringBinding(this.getUsageLabel(), this.ingredient.get().idProperty()));
});
this.nutritionValueContainer.addEventHandler(KeyEvent.KEY_RELEASED, event -> {
if (event.getCode() != KeyCode.ENTER) {
@ -101,7 +107,15 @@ public class NutritionDetailsCtrl implements LocaleAware {
@Override
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) {
@ -134,6 +148,7 @@ public class NutritionDetailsCtrl implements LocaleAware {
public LocaleManager getLocaleManager() {
return manager;
}
public void handleNutritionSaveClick(ActionEvent actionEvent) throws IOException, InterruptedException {
Ingredient newIngredient = updateIngredient();
this.ingredient.get().updateFrom(server.updateIngredient(newIngredient));

View file

@ -1,10 +1,14 @@
package client.scenes.nutrition;
import com.google.inject.Inject;
import javafx.fxml.FXML;
public class NutritionViewCtrl {
@Inject
public NutritionViewCtrl(
) {
}
@FXML
NutritionDetailsCtrl nutritionDetailsController;
}

View file

@ -411,6 +411,17 @@ public class RecipeDetailCtrl implements LocaleAware {
addToListButton.setText(getLocaleString("app.word.shop"));
scaleLabel.setText(getLocaleString("app.word.scale"));
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

View file

@ -12,6 +12,6 @@
prefHeight="400.0" prefWidth="600.0">
<SplitPane>
<fx:include source="IngredientList.fxml" />
<fx:include source="NutritionDetails.fxml" />
<fx:include fx:id="nutritionDetails" source="NutritionDetails.fxml" />
</SplitPane>
</AnchorPane>