Log message #4266107

# At Username Text
# Jun 22nd 2021, 11:58 david I am trying to do a dropdown menu for changing the language of the current url
# Jun 22nd 2021, 11:56 kevin.pfeifer besides the fact, that multiple translation "keys" can have the same translation, so you could run into the problem, that your given "translated text" appears multiple times in your .po file
# Jun 22nd 2021, 11:54 kevin.pfeifer maybe you try to fix a problem which can be done easier otherwise
# Jun 22nd 2021, 11:53 kevin.pfeifer but what are you trying to accomplish with that?
# Jun 22nd 2021, 11:52 kevin.pfeifer and search through that manually if you really really want to
# Jun 22nd 2021, 11:52 kevin.pfeifer you can ge tthe whole translation package via ``` $translator = I18n::getTranslator(); $package = $translator->getPackage();```
# Jun 22nd 2021, 11:52 erwane the `__` function call ` ```I18n::getTranslator()->translate($singular, $args);``` You can set you own translator, who search in ALL pot files for string and return original.
# Jun 22nd 2021, 11:50 erwane but it's very weird request ;)
# Jun 22nd 2021, 11:50 erwane Maybe you can write you own translator
# Jun 22nd 2021, 11:44 david If I set a locale in runtime via I18n::setLocale(), I can get the translation of a string. Is there any way to do in the inverse way? Given a translation, get the original string.
# Jun 22nd 2021, 11:42 david morning :)
# Jun 22nd 2021, 11:39 kevin.pfeifer But I guess all these structures have their meaning and reason, even if we sometimes don't get it instantly :)
# Jun 22nd 2021, 11:39 kevin.pfeifer to be honest i too had to fiddle with these things quite some time till i got it working :)
# Jun 22nd 2021, 11:38 neon1024 Success! Thanks again for the tips @kevin.pfeifer appreciate the help
# Jun 22nd 2021, 11:35 neon1024 The fact that CookieCollection is immutable caught me out
# Jun 22nd 2021, 11:21 neon1024 Might be time for a coffee break ,:)
# Jun 22nd 2021, 11:19 neon1024 Oh, good spot
# Jun 22nd 2021, 11:19 kevin.pfeifer you need to set the CookieColleciton on the response, not the request
# Jun 22nd 2021, 11:19 kevin.pfeifer you mixed request and repsonse there FYI
# Jun 22nd 2021, 11:18 kevin.pfeifer would be something like ```$cookie_collection = $this->getRequest()->getCookieCollection()->add($cookie); $new_response = $this->getResponse()->withCookieCollection($cookie_collection) $this->setResponse($new_response);```
# Jun 22nd 2021, 11:17 neon1024 Thanks @kevin.pfeifer I’ll give this approach a try :bow:
# Jun 22nd 2021, 11:17 kevin.pfeifer can ge quite lengthy :)
# Jun 22nd 2021, 11:17 kevin.pfeifer and if you want to stick to the getter/setter methods sure
# Jun 22nd 2021, 11:16 kevin.pfeifer thats why I always like to make a copy of the request with `$request = $this->getRequest()` and work with that variable unless i need to set it back
# Jun 22nd 2021, 11:16 neon1024 imeanimsureitcouldbelongerifwejustaddedsomemorenestedmethodsintotherebutyoucantbetoocarefullthesedaysyouknow
# Jun 22nd 2021, 11:16 kevin.pfeifer ,:)
# Jun 22nd 2021, 11:16 neon1024 `$this->setRequest($this->getRequest()->withCookieCollection($this->getRequest()->getCookieCollection()->add($cookie)));` oof
# Jun 22nd 2021, 11:15 slackebot1 'pages', 'action' => 'display', 'success' ] );```
# Jun 22nd 2021, 11:15 kevin.pfeifer ``` // Only save cookie if user selected it if(!empty($data['remember_my_data'])){ $cookie = Cookie::create( 'remember_my_data', $data ); $this->response = $this->response->withCookie( $cookie ); } else { $this->response = $this->response->withExpiredCookie(new Cookie('remember_my_data')); } return $this->redirect( [ 'controller' =>
# Jun 22nd 2021, 11:15 kevin.pfeifer I don’t return the response instance, i just do a redirect
# Jun 22nd 2021, 11:15 kevin.pfeifer or whatever
# Jun 22nd 2021, 11:15 kevin.pfeifer before redirecting
# Jun 22nd 2021, 11:15 kevin.pfeifer could be that you need to adjust the returned cookie collection as well
# Jun 22nd 2021, 11:14 neon1024 …and return that response instance I suppose?
# Jun 22nd 2021, 11:14 kevin.pfeifer but you need to set it back into the response as well
# Jun 22nd 2021, 11:14 kevin.pfeifer well your code above returns the new cookie collection
# Jun 22nd 2021, 11:13 neon1024 Not an intuitive api for sure imho
# Jun 22nd 2021, 11:12 neon1024 I wonder what all this CookieCollection business is about then :thinking_face:
# Jun 22nd 2021, 11:12 kevin.pfeifer i did it like that
# Jun 22nd 2021, 11:12 neon1024 I guess it just dies when the request instance does
# Jun 22nd 2021, 11:12 kevin.pfeifer ``` $cookie = Cookie::create( 'remember_my_data', $data ); $this->response = $this->response->withCookie( $cookie );```