Ruby on Rails: how to change the language of error messages? - ruby-on-rails-3

Now I want to use error.full_messages to display the error messages. But it's default language is English. I want to show other language's error message. How can I do that? Or I have to self define something?
Thank you!

Assuming you're referring to error messages for your models, you can internationalize your error messages in your locale yaml files using the activerecord.errors key. For example:
en:
activerecord:
errors:
models:
user:
attributes:
name:
blank: can't be blank
email:
blank: can't be blank
invalid: is invalid
password:
too_short: is too short (minimum is 6 characters)
See section 5.1.1 of the Rails i18n guide for more details on i18n-izing error messages.

Related

Getstream.io throws exception when using the "to" field

I have two flat Feed Groups, main, the primary news feed, and main_topics.
I can make a post to either one successfully.
But when I try to 'cc' the other using the to field, like, to: ["main_topics:donuts"] I get:
code: 17
detail: "You do not have permission to do this, you got this error because there are no policies allowing this request on this application. Please consult the documentation https://getstream.io/docs/"
duration: "0.16ms"
exception: "NotAllowedException"
status_code: 403
Log:
The request didn't have the right permissions or autorization. Please check our docs about how to sign requests.
We're generating user tokens server-side, and the token works to read and write to both groups without to.
// on server
stream_client.user(user.user_id).create({
name: user.name,
username: user.username,
});
Post body:
actor: "SU:5f40650ad9b60a00370686d7"
attachments: {images: [], files: []}
foreign_id: "post:1598391531232"
object: "Newsfeed"
text: "Yum #donuts"
time: "2020-08-25T14:38:51.232"
to: ["main_topics:donuts", "main_topics:all"]
verb: "post"
The docs show an example with to: ['team:barcelona', 'match:1'], and say you need to create the feed groups in the panel, but mention nothing about setting up specific permissions to use this feature.
Any idea why this would happen? Note that I'm trying to create the new topics (donuts, all) which don't exist when this post is made. However, the docs don't specify that feeds need to be explicitly created first - maybe that's the missing piece?
If you haven’t already tried creating the feed first, then try that. Besides that, the default permissions restrict a user from posting on another’s feed. I think it’s acceptable to do this if it’s a notification feed but not user or timeline.
You can email the getstream support to change the default permissions because these are not manageable from the dashboard.
Or you can do this call server side as an admin permissions.

How can I change the price format used in email templates?

I need to send an email notification when a new Order is received and I need the price to be formatted in a different way than the rest of the site.
Is there a way to send parameters to oro_format_price?
I tried to replace oro_format_price with a simple number_format but it didn't work...
Thanks
Edit:
Digging around the code (Here and here) I found there are options to be passed to oro_format_price filter so I put this code in my email template:
{{ item.price.value|oro_format_price({symbols: {decimal_separator_symbol: '.', grouping_separator: '' }}) }}
Which is not showing me any error, but I'm not getting any email either :(
I'm using version 3.1.17 BTW
Edit 2:
I've checked again and I found somethings I had written wrong, my current version looks like this:
{{ item.price|oro_format_price({symbols: {decimal_separator_symbol: '.', grouping_separator_symbol: '', monetary_grouping_separator_symbol: '', currency_symbol:'' }}) }}
Now the email is sent but the format is not changed :(
Edit 3:
I changed it again to try and use a simpler way:
{{ item.price.value|number_format(2, '.','') }}
and found these errors in the log:
app.ERROR: An error occurred while processing notification {"exception":"[object] (Oro\\Bundle\\EmailBundle\\Exception\\EmailTemplateCompilationException(code: 0): Could not found one email template with \"order_confirmation_test\" name for \"Oro\\Bundle\\OrderBundle\\Entity\\Order\" entity at /usr/share/nginx/html/oroapp/vendor/oro/platform/src/Oro/Bundle/EmailBundle/Provider/EmailTemplateContentProvider.php:71)"} []
app.ERROR: An error occurred while sending "Oro\Bundle\NotificationBundle\Event\Handler\TemplateEmailNotificationAdapter" notification with email template "order_confirmation_test" for "Oro\Bundle\OrderBundle\Entity\Order" entity {"exception":"[object] (Oro\\Bundle\\NotificationBundle\\Exception\\NotificationSendException(code: 0): Could not send notification of type \"Oro\\Bundle\\NotificationBundle\\Event\\Handler\\TemplateEmailNotificationAdapter\" for email template \"order_confirmation_test\" for \"Oro\\Bundle\\OrderBundle\\Entity\\Order\" entity at /usr/share/nginx/html/oroapp/vendor/oro/platform/src/Oro/Bundle/NotificationBundle/Manager/EmailNotificationManager.php:125)"} []
I tried to output the same through a regular template (outside of an email I mean) and it worked ok.
Looking at php error_log file I found this message:
"NOTICE: PHP message: PHP Notice: Calling "getvalue" method on a "Oro\Bundle\CurrencyBundle\Entity\Price" object is not allowed in ...
I checked the class Oro\Bundle\CurrencyBundle\Entity\Price and the getValue method is public so I don't understand why this is failing :(
Email templates have a separate twig rendering engine with a limited list of available functions. This is achieved using the sandbox extension.
To expose a function to the email rendering engine you can use Oro\Bundle\EmailBundle\DependencyInjection\Compiler\AbstractTwigSandboxConfigurationPass.
For example, see an existing implementation, like \Oro\Bundle\PaymentBundle\DependencyInjection\Compiler\TwigSandboxConfigurationPass

Change coupon.invalid.code.provided text as GlobalMessage

I'm trying to display the custom message, Invalid voucher code. when applying an invalid voucher code.
I see the GlobalMessage voucher.applyVoucherSuccess defined in cart-voucher.effect.ts
and its actual text in the translations/en/cart.ts file
But how can I edit the error message when there's an invalid voucher code input?
Or if there's an easier way of doing it in spartacus?
Currently, there's no easy way or best to do in Spartacus until further notice. However, we do have a way to change the error message for invalid voucher code.
For example, look at the bad-request.handler.ts.
You can catch the specific error, which is VoucherOperationError. Using this error.type from the error response of {message: "coupon.invalid.code.provided", type: "VoucherOperationError"}, you can point to the translations key or your custom message using the raw property.

Request body does not show up in curl example with OpenApi3 + widdershins + shins

I am generating API documentation for our Java endpoints. I am using widdershins to convert our openAPI3.0 yaml file to markdown. Then, I am using shins to convert the markdown file to html. The request body for all of our endpoints does not appear in the generated cURL examples. Why is this? This defeats the purpose of having cURL examples because copying and pasting a cURL example without the required body will not work. Can anyone recommend a workaround or alternative tool that generates good documentation with complete cURL examples?
Example endpoint from our openAPI.yaml file...
post:
tags:
- Tools
description: Installs a tool on a user's account
operationId: Install Tool
requestBody:
description: UserTool object that needs to be installed on the user's account
content:
application/json:
schema:
$ref: '#/components/schemas/UserTool'
required: true
parameters:
responses:
default:
description: default response
content:
application/json:
schema:
$ref: '#/components/schemas/Message'
This is the documentation our toolchain generates from this yaml file...
We would like to add a line just like the one below (grey highlight) to our cURL examples. This is a chunk from the markdown file that Widdershins produces from our openAPI yaml file. I manually added the –“d
This stack overflow Q/A suggests the answer is it is impossible to include a body parameter in a code example using swagger or openAPI. Is this correct? If so, why is this the case? What's the reasoning?
Cheers,
Gideon
I also had the same problem.
As a result of trial and error, it was found that the behavior displayed on curl varies depending on the in value.
Please look at the ParameterIn enum.
public enum ParameterIn {
DEFAULT(""),
HEADER("header"),
QUERY("query"),
PATH("path"),
COOKIE("cookie");
I tried by like below at first time:
new Parameter().name("foo").in(ParameterIn.HEADER.name())
But name return like "HEADER", So swagger(or OpenAPI) recognized to header.
It should be lower character like "header" follow ParameterIn enum.
So, you can fix it like this
new Parameter().name("foo").in(ParameterIn.HEADER.toString())
or
new Parameter().name("foo").in("header")
I also encountered the same problem and I did a little digging. It turns out I had to set options.httpSnippet option in widdershins to true so that the requestBody params will show up. However, setting that to true just shows the params if content type is of application/json. For multipart-form-data, you need to set options.experimental to true as well.
Unfortunately, there is a bug in widdershins for handling application/x-www-form-urlencoded content-type.. I created a PR for it which you can probably manually patch on the widdershins package. PR link: https://github.com/Mermade/widdershins/pull/492/files

Registering a Shopify Webhook via the ShopifyAPI gem

This call correctly returns an empty array:
hooks = ShopifyAPI::Session.temp(s.myshopify_domain, s.shopify_access_token) do
ShopifyAPI::Webhook.find :all
end
While this call always returns a 403:
hook = ShopifyAPI::Session.temp(s.myshopify_domain, s.shopify_access_token) do
ShopifyAPI::Webhook.create(
format: 'json',
topic: 'orders/fulfilled',
address: "http://www.something.fr/api/webhooks?store_id=#{s.id }&store_check=#{ s.checksum }"
)
end
I've tried pretty much all solutions offered over various websites, each time with a failure.
What am I missing here?
The whole code block given in original post is correct.
It was in fact a rights problem, the customer who provided us with the API tokens didn't enable webhook creation rights on the Shopify configuration.
It might seem like nothing, but it is critical that you check that with whoever gave you credentials!
Try this
hook = ShopifyAPI::Session.temp(s.myshopify_domain, s.shopify_access_token) do
ShopifyAPI::Webhook.new(
format: 'json',
topic: 'orders/fulfilled',
address: "http://www.something.fr/api/webhooks?store_id=#{s.id }&store_check=#{ s.checksum }"
)
end
Possible duplicate: Error Creating Shopify Webhook through the API