Symfony2 - "Invalid Resource Exception" when translating twig template - symfony

I am trying to translate labels in my twig template located in Resources/views/User/ folder:
<label for="username">{% trans %}Username{% endtrans %} </label>
And the following is a section from my login.ka.xliff file located in my project under "translations" folder:
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>Username</source>
<target>მომხმარებელი</target>
</trans-unit>
</body>
</file>
</xliff>
and this is my route to the login page:
login:
path: /login/{_locale}
defaults: { _controller: ExampleBundle:LogIn:login }
requirements:
_locale: en|ka
I have two problems:
When I try to open the login page with a locale (say, ka) I get the:
500 Internal Server Error - Twig_Error_Runtime
1 linked Exception:
InvalidResourceException »
I know I can get the locale from request using $request->getLocale(); but how do I specify that login page should use login.ka.xliff file for translations?
Ok, I seem to have provided not enough info, so here it is:
I put my translation file in Example:MyBundle:Resources:translations (this is what I meant above "in my project").
I get exception when rending my login view and the following is the full version of the exception I get:
"An exception has been thrown during the rendering of a template ("") in ExampleMyBundle:User:login.html.twig at line 32.
500 Internal Server Error - Twig_Error_Runtime
1 linked Exception:
InvalidResourceException »"
And yes, I did try clearing cache each time I made changes, but it didn't help.
And also, I added the complete version of my login.ka.xliff file.
Thanks again!

Your xliff file seems to be invalid - it should look like this: ( containing the xml-namespace, body, ... ).
<!-- messages.ka.xliff -->
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>Username</source>
<target>მომხმარებელი</target>
</trans-unit>
</body>
</file>
</xliff>
The file should be named messages.ka.xliff if you haven't actually specified a different translation domain in your template!
{{ 'Username'|trans({}, "login") }}
... or configured a different default translation-domain in your template ...
{% trans_default_domain "login" %}
<trans-unit id="1">
<source>Username</source>
<target>მომხმარებელი</target>
</trans-unit>
... is an invalid xliff-file.

Related

HERE GET batch geocoding response 403 but job is complete

I successfully submitted a batch geocoding request...
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:SearchBatch xmlns:ns2="http://www.navteq.com/lbsp/Search-Batch/1">
<Response>
<MetaInfo>
<RequestId>CAOxHo4SFaj17sSB2UyTxeoDKHZR77f9</RequestId>
</MetaInfo>
<Status>accepted</Status>
<TotalCount>0</TotalCount>
<ValidCount>0</ValidCount>
<InvalidCount>0</InvalidCount>
<ProcessedCount>0</ProcessedCount>
<PendingCount>0</PendingCount>
<SuccessCount>0</SuccessCount>
<ErrorCount>0</ErrorCount>
</Response>
</ns2:SearchBatch>
And when I GET status, the job is completed....
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:SearchBatch xmlns:ns2="http://www.navteq.com/lbsp/Search-Batch/1">
<Response>
<MetaInfo>
<RequestId>CAOxHo4SFaj17sSB2UyTxeoDKHZR77f9</RequestId>
</MetaInfo>
<Status>completed</Status>
<JobStarted>2019-10-31T00:11:58.000Z</JobStarted>
<JobFinished>2019-10-31T00:12:26.000Z</JobFinished>
<TotalCount>13291</TotalCount>
<ValidCount>13291</ValidCount>
<InvalidCount>0</InvalidCount>
<ProcessedCount>13291</ProcessedCount>
<PendingCount>0</PendingCount>
<SuccessCount>13291</SuccessCount>
<ErrorCount>0</ErrorCount>
</Response>
However, when I then go to get the response, I get 403 forbidden
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<h1>Forbidden</h1>
<p>You don't have permission to access /
on this server.</p>
</body>
</html>
I am using the endpoint outlined here: https://developer.here.com/documentation/batch-geocoder/topics/example-get-results.html
In this case you need to pass correct apikey to download the result.
https://batch.geocoder.ls.hereapi.com/6.2/jobs/CAOxHo4SFaj17sSB2UyTxeoDKHZR77f9/result?apiKey={}
Also refer https://developer.here.com/documentation/batch-geocoder/dev_guide/topics/example-get-results.html

Symfony 4 translation are not working

the problem is not symfony, is me lol, I need help cause is not working fine, when i change my locale the text is still in english, there is my code
translation.yaml
framework:
default_locale: '%locale%'
translator:
paths:
- '%kernel.project_dir%/translations'
fallbacks:
- '%locale%'
framework.yaml
framework:
secret: '%env(APP_SECRET)%'
default_locale: en
csrf_protection: true
On my FrontController
`/**
* #Route("/{_locale}/",
* requirements={"_locale"="en|es"},
* name="index")
*/
public function index()
{
if($this->getUser()){
return $this->redirectToRoute('index');
}else{
$register= new Register();
$form = $this->createForm(RegisterType::class, $register,array(
'empty_data'=>'user_register',
'validation_groups' => array('default', 'empty_data'),
));
}`
my messages.es.xlf
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="sign_in">
<source>Sign in</source>
<target>Entrar</target>
</trans-unit>
</body>
</file>
on my template
{{ 'Sign in'|trans }}
well, the problem, is i change my url http://...../en/ to http://..../es/ is not working, but if i change my fallback manuale to es on translation.yaml is working fine, but then dons't work on /en/ any idea??

Handle frontend login and authentication via LDAP

I've created a MPGW policy to add a front page to authenticate before go to backside :
Requests Rules:
Rule1 : Matchrule: /favicon.ico
Rule2: Matchrule: /loginpage.html Transform: xsl stylesheet to dispaly a html loginpage and add the login & password at the query params in the URL
Rule3: Matchrule: /wps/portal/Home Transform: xsl stylesheet to extract login/passwrd from URL and authenticate user with a LDAP (dp:ldap-authen()) and write result in a context variable
and here is my problem:
Response Rules:
Rule4: Matchrule: "/" Transform : xsl stylesheet " i want to do: if context variable is OK nothing to do else display an error page html " !!!??
i've written in the response stylesheet something like :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions" xmlns:re="http://exslt.org/regular-expressions"
extension-element-prefixes="dp re"
exclude-result-prefixes="dp re">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:if test="string-length(dp:variable('var://context/LDAP_Auth_Status')) = 0">
<!--ERROR-->
<html>
<head>
<title> Error Page</title>
</head>
<body>
<h2> Error USER VALIDITY </h2>
<strong>doom!!</strong>
</body>
</html>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
First, Rule4: Matchrule: "*" should be an asterisk if you want it to match anything.
Secondly, is there a backside response?
Else you have to add a var://service/skip-backside=1 if the Response rule should be run. It wil go to Error rule otherwise.
Also it is good practice to not add values into the context. You should use context variables, e.g.:
var://context/LDAPInfo/LDAP_Auth_Status
You can use <xsl:message pd:priority="debug"> to add information into the logs for easier way to find values. Also use the Probe to find Context variable values and see how the flow runs.

EasyAdminBundle entities labels translations

I'm unable to configure translations. My config.yml has (among others) this entry:
easy_admin:
entities:
Blog:
label: app.blog
class: AppBundle\Entity\Blog
I've also created a translation resorce: messages.es.xliff with this entry:
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="es" target-language="es" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="app.blog">
<source>app.blog</source>
<target>Blog</target>
</trans-unit>
</body>
</file>
</xliff>
but the translated literal doesn't appear in the left menu.
Thank you very much for your help.
At last I've changed the name of translation ressource to EasyAdminBundle.es.yml and now everything works fine.
Ensure you have the translator service enabled. In app/config/config.yml:
framework:
translator: { fallbacks: ["en"] }

Symfony2: twig filters inside transchoice

I am using Symfony2, Twig and xliff based translations.
Now, I want to show text based on a numerical value which is between [-Inf,Inf]. To do that, I use transchoice.
My problem: I want to display 7 days ago if count=-7. However, I get -7 days ago. I can't use twig filters like abs inside transchoice fields, right? How do I remove the leading minus sign.
Here is my message.en.xliff...
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>todo.days-difference</source>
<target>{0} today|{1} tommorow|]1,14] %count% days before|]14,Inf] far away|{-1} yesterday|[-14,-1[{{ count }}%count% days after|[-Inf,-14[ long after</target>
</trans-unit>
</body>
</file>
</xliff>
passing the absolute value of the count variable as argument solves the problem:
{{ "todo.days-differences"|transchoice(task.getDueDateDifference(), {'%count_abs%': task.getDueDateDifference()|abs}) }}
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>todo.days-difference</source>
<target>{0} today|{1} tommorow|]1,14] %count_abs% days before|]14,Inf] far away|{-1} yesterday|[-14,-1[ %count_abs% days after|[-Inf,-14[ long after</target>
</trans-unit>
</body>
</file>
</xliff>

Resources