Translation of a Title in Laravel Doesn't Work - laravel

I got this notification (resources/views/vendor/notifications/email.blade.php):
#lang( "If you’re having trouble clicking the ":actionText" button,
copy and paste the URL below\n". 'into your web browser:
:actionURL', [ 'actionText' => $actionText, 'actionURL' => $actionUrl])
Now I'd like to translate that one using de.json in resource/lang-directory:
{
"If you’re having trouble clicking the \":actionText\" button,
copy and paste the URL below into your web browser: [:actionURL] .
(:actionURL)": "Falls Du Probleme dabei hast, den \":actionText\"
Button anzuklicken, rufe folgende URL auf: [:actionURL](:actionURL)"
}
All other translations I created this way are working fine. How can I solve that?

Simply remove the concatenation dot and put all words in the same string, like this:
{
"If you’re having trouble clicking the \":actionText\" button, copy and paste the URL below\ninto your web browser: [:actionURL](:actionURL)" : "Caso não seja possível clicar no botão \":actionText\", copie e cole no seu navegador o endereço a seguir: [:actionUrl](:actionUrl) \n",
}

If you use laravel 6,7 try remove ":actionURL"
example:
"If you’re having trouble clicking the \":actionText\" button, copy and paste the URL below\ninto your web browser: ": "Falls Du Probleme dabei hast, den \":actionText\" Button anzuklicken,\nrufe folgende URL auf: "

in laravel 6 or above, you can use this in lang.json file:
"If you’re having trouble clicking the \":actionText\" button, copy and paste the URL below\ninto your web browser:": "translation into your favorite language"
no need to use ['actionText' => $actionText,] at the end of message

Related

Unable to click download button with web scraper

for whatever reason mechanize is unable to click this export button to automate downloading a public government csv file, i'm trying to automate downloading a fishing report, does anyone have any ideas on how to get it to work?
agent = Mechanize.new
url = 'https://nrm.dfg.ca.gov/FishPlants/'
log :debug, "reading HTML from #{url}"
page = agent.get(url)
log :debug, 'loaded page'
form = page.search('#aspnetForm').first
button = page.search('.application_button').first
log :debug, 'clicking Export button'
response = agent.submit(form, button)
i get a stack trace with the following error
...
form.add_button_to_query(button) if button
^^^^^^^^^^^^^^^^^^^^
/Users/aronlilland/.rvm/gems/ruby-3.1.2/gems/mechanize-2.8.5/lib/mechanize.rb:581:in `submit'
/Users/aronlilland/Documents/dev/fishing-report/tasks/download/fishing_report.rake:27:in `block (2 levels) in <top (required)>'
Tasks: TOP => download:fishing_report
(See full trace by running task with --trace)
the form is confirmed returns successfully, but the button is an input field
the page seems relatively straight forward, so dont know why i'm unable to scrape it - and its also public data
<form method="post" action="./" id="aspnetForm">
<!-- .... -->
<input
type="submit"
name="ctl00$cphContentMiddle$btnExport"
value="Export"
id="ctl00_cphContentMiddle_btnExport"
class="application_button"
>
<!-- .... -->
</form>
agent.submit got the wrong type for form
The issue here could be seen if you had included the beginning of the stack trace:
.../ruby/gems/3.1.0/gems/mechanize-2.8.5/lib/mechanize.rb:581:in `submit': undefined method `add_button_to_query' for #<Nokogiri::XML::Element:0x1ea14 name="form" attributes=
[#<Nokogiri::XML::Attr:0xbd38 name="method" value="post">, ...
Mechanize expects the submit to act on a Mechanize::Form instance, but instead got an instance of Nokogiri::XML::Element, as you can see by adding this to your code:
form.class # => Nokogiri::XML::Element
If you check the docs for the Mechanize::Form class, you can see the example they give to get you the form object is this:
form = page.forms.first # => Mechanize::Form
as opposed to what you used:
form = page.search('#aspnetForm').first
The call to search here is delegated to Nokogiri, and therefore doesn't return the object type you need, but rather a Nokogiri element.
button also has the wrong type
By the way the same applies to this line:
button = page.search('.application_button').first
If you fix the type of form, you'll get into a similar issue with button not being the expected type. Again, there's an example in the docs showing how a button is found:
agent.submit(page.forms.first, page.forms.first.buttons.first)
You'll need to figure out how to find the specific button you need though, I haven't worked with Mechanize before, so I can't offer a suggestion here. Presumably there's a way to convert the button you find through search to a Mechanize::Form::Button instance.

CKEDITOR4 Mentions Plugin with ajax : javascript error

I have a javascript error using CKEDITOR 4 and the Mentions Plugin.
I can't solve this problem for 2 days, I'm stuck.
I've used the online builder to get CKEDITOR + Mentions plugin.
See my build here: https://ckeditor.com/cke4/builder/fbe187b32ec7c025e28e01a537c72c62
With the following configuration it works fine: I see the drop down list with the names : Anna, Thomas, John
CKEDITOR.config.mentions = [{feed: ['Anna', 'Thomas', 'John']}];
However, when doing an ajax call to get the data, I got a javascript error:
The script /ajax_mention.php
displays
["Anna", "Thomas", "John"]
with the following configuration :
CKEDITOR.config.mentions = [{feed: '/ajax_mention.php'}];
when I type in the editor "#anna", the names do not display
the /ajax_mention.php script is launched and displays the correct data (when I look at the "network" tab on Chrome. see screenshot)
["Anna", "Thomas", "John"]
However, this triggers a javascript error (looking at the Chrome console tab. see screenshot)
ckeditor.js?1645882460:916 Uncaught TypeError: Cannot read properties of null (reading 'addClass')
at g.selectItem (ckeditor.js?1645882460:916:473)
at d.onSelectedItemId (ckeditor.js?1645882460:912:276)
at f.q (ckeditor.js?1645882460:10:246)
at f.fire (ckeditor.js?1645882460:12:91)
at f.select (ckeditor.js?1645882460:920:294)
at f.selectFirst (ckeditor.js?1645882460:920:371)
at d.open (ckeditor.js?1645882460:910:503)
at d.modelChangeListener (ckeditor.js?1645882460:911:234)
at f.q (ckeditor.js?1645882460:10:246)
at f.fire (ckeditor.js?1645882460:12:91)
See screen copy:
https://polyglotclub.com/bug_ckeditor_mentions.jpg
screen copy
The solution was given by the Ckeditor team : see https://github.com/ckeditor/ckeditor4/issues/5107
When we use a hardcoded data in the array, such as ['Anna, 'Geralt'] the createArrayFeed() function changes the input structure from the mentioned above to:
[
{
id: 1,
name: 'Anna'
},
{
id: 2,
name: 'Geralt'
}
]
I've just adjusted data on the backend side to the structure above.

Pass dynamic content to template in Middleman

I'm building a static site using Middleman that has a portfolio section of all the client's recent projects.
The portfolio section will display project thumbnail images in a 3 X 3 gallery fashion and, when clicked on, will open their co-responding html page inside a lightbox.
The layout for the pages inside the light box is the same so rather than markup each individual page, I thought there would be a way for Middleman handling the content served from a yaml data file (projects.yml) using [a link.
Here's what I've got in my config.rb file
###
# Page options, layouts, aliases and proxies
###
# A path which all have the same layout
with_layout :popup do
page "/projects/*"
end
# Proxy (fake) files
# page "/this-page-has-no-template.html", :proxy => "/template-file.html" do
# #which_fake_page = "Rendering a fake page with a variable"
# end
data.projects.details.each do |pd|
proxy "/projects/#{pd[:client_name]}.html", "/projects/template.html", locals: { project: pd }, ignore: true
end
Ok so after some digging I came across the two posts below which helped me under stand how dynamic pages work in middleman. (Unfortunately there's not a lot of doco and the Middleman example for Dynamic pages is really basic)
http://benfrain.com/understanding-middleman-the-static-site-generator-for-faster-prototyping/
http://forum.middlemanapp.com/discussion/134/best-way-to-use-yaml-same-html-but-parameter-driven-data-fixed/p1
My solution...
data/projects.yml (contains project details)
details:
- client: "Company X"
title: "Company X Event"
video_url: ""
logo:
- "logo_companyx.gif"
image_path: "/img/projects/companyx"
total_images: 10
content: "<p>Blah blah blah</p>"
responsibilities:
"<li>Something</li>
<li>Some task</li>"
config.rb:
data.projects.details.each do |pd|
proxy "/projects/#{pd[:client]}.html", "/projects/template.html", :layout => false, :locals => { :project => pd }, :ignore => true
end
The trick with the snippet above is passing the entire project data object to the template via a proxy using locals and setting the layout to false so it doesn't inherit the default site layout (as I - or the client rather - want to display these in a lightbox popup)
The last step in the process was to create /projects/template.html.erb (in the source folder), declaring the following at the top of the template
<% p = locals[:project] %>
This allowed me to output each property of the p object within template.html.erb.
eg:
<%= p[:title] %>
I hope this helps someone as it took me a few days of playing around and LOTS of searching online for example or hints.

How can I concatenate multiple variables in my MVC3 Razor code?

I have some razor code and I am having a problem with getting the syntax working. The code is as follows:
else
{
#(x.RowKey.Substring(0, 2).TrimStart('0') + "." + x.RowKey.Substring(2, 2).TrimStart('0').PadLeft(1, '0')) - #Html.Raw(x.Title)<br>
}
This is giving me the following error:
Compiler Error Message: CS1002: ; expected
When you start your #(x.RowKey...., Razor still thinks that it's still in C# mode, not HTML mode (to use the totally non-technical terms). Nick Bork's suggestion about wrapping that stuff in the <text> tags gets the page back into HTML mode so you can go back to using your normal Razor syntax.
Try this:
else
{
var st = x.RowKey.Substring(0, 2).TrimStart('0') + "." + x.RowKey.Substring(2, 2).TrimStart('0').PadLeft(1, '0'));
#st - #Html.Raw(x.Title)<br/>
}

How to save a html5 canvas.toDataURL as a png file on the server using Seaside

I have an image that users can annotate on the browser. I can access the image using
canvas.toDataURL()
...I'd like to add a 'save' option for the user to save the image on the server.
This question has been answered for php...
file_put_contents('test.png', base64_decode(substr($data, strpos($data, ",")+1)));
...what I need is a Seaside callback with the PNG file content.
Is there a way to do this in Seaside?
Johan pointed out that the mine type declaration has to be removed from the value string. This works in VW... (with string hack to remove 'data:image/png;base64,')
html jQuery ajax
callback: [:value |
| writestream string |
writestream := ('c:\data\sketchpad_image.png' asFilename withEncoding: #binary) writeStream.
string := value copyFrom: 23 to: value size.
[writestream nextPutAll: (Seaside.GRPlatform current base64Decode: string) asByteArray]
ensure: [writestream close] ]
value: (Javascript.JSStream on: 'sketchpadCanvas.toDataURL()')
Depending on how you want your website to behave, I guess there are multiple ways of doing it. Here is the raw sample of one possibility I can think of using a jQuery ajax callback:
html jQuery ajax
callback: [:value | (FileStream newFileNamed: 'test.png')
nextPutAll: (value copyFrom: ((value indexOf: $,) + 1 to: value size) base64Decoded ]
value: (JSStream on: 'canvas.toDataURL()')
I did not test this myself. Maybe the filestream needs to be sent the #binary message to make a correct png file. Let me know if there are troubles.
Hope it helps.
Does the file-upload section in the Seaside book solve your problem? Taking the code from the book:
UploadForm>>renderContentOn: html
html form multipart; with: [
html fileUpload
callback: [ :value | self receiveFile: value ].
html submitButton: 'Send File' ]
UploadForm>>receiveFile: aFile
| stream |
stream := (FileDirectory default directoryNamed: 'uploads')
assureExistence;
forceNewFileNamed: aFile fileName.
[ stream binary; nextPutAll: aFile rawContents ]
ensure: [ stream close ]
I've also published a blog post about how to manage file uploads in a production environment using Seaside and Nginx that may be of interest.

Resources