In the Gallery
component, I have language code:
function Gallery(LanguageService) {
var $ctrl = this;
$ctrl.$onInit = function () {
$ctrl.code = LanguageService.language;
_loadGallery($ctrl.code);
}
}
The LanguageService
is a service that holds global language settings. For instance, codes like en
for English and pl
for Polish. When moving from the Gallery
to the Image details
component, the $onInit
process remains the same - extract the code from the language and load data. The issue arises when adding image translations; for example, German translation with code de
. This change affects the LanguageService
, leading to mismatched languages:
- The
Image
displays in German - Clicking on the
Go back
button redirects to the Gallery - The Gallery lacks German translation results in a
404 Not Found
error
One solution could be passing the galleryLanguage
state to the Image
:
$state.go("image.details", {id: image.id, galleryLanguage: $ctrl.language});
Yet, it's cumbersome without explicit definition in each image
state; for example, transitioning from image.details
to
image.edit</code requires:</p>
<pre><code>$state.go("image.edit", {id: image.id, galleryLanguage: $ctrl.language});
// To return to the gallery
function goBackToGallery() {
$state.go(`gallery.details`, {galleryLanguage: $ctrl.galleryLanguage}); // then used in the Gallery if present
}
Alternatively, an additional service can handle this scenario:
function Gallery(LanguageService, TemporaryService) {
var $ctrl = this;
$ctrl.$onInit = function () {
$ctrl.code = TemporaryService.language? TemporaryService.language : LanguageService.language;
TemporaryService.language = undefined;
_loadGallery($ctrl.code);
}
function goToImageDetails(image) {
TemporaryService.language = String($ctrl.code);
$state.go('image.details', {id: image.id});
}
}
Perhaps Angular UI router offers a solution without custom implementation. Appreciate all assistance provided.