Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I'm building a Laravel application that supports multiple languages. All was going OK but now i'm facing problem translating the pagination display numbers. I have tried to search for solution but don't find any. Any simple demonstration will be helpful.
Thanks
you can publish the pagination views into your project, use the php artisan command
php artisan vendor:publish --tag=laravel-pagination
this artisan command create a new folder and files in
resources/views/vendor/pagination
see https://laravel.com/docs/7.x/pagination#customizing-the-pagination-view
for more details
you can customize your view by creating views like pagination.blade.php and use
{{ $paginator->links('pagination') }}
for format your numbers in any language numerals like Bengali you can add a helper method like this in helper file:
function toBengaliNum($number)
{
$number = str_replace("1", "১", $number);
$number = str_replace("2", "২", $number);
$number = str_replace("3", "৩", $number);
$number = str_replace("4", "৪", $number);
$number = str_replace("5", "৫", $number);
$number = str_replace("6", "৬", $number);
$number = str_replace("7", "৭", $number);
$number = str_replace("8", "৮", $number);
$number = str_replace("9", "৯", $number);
$number = str_replace("0", "০", $number);
return $number;
}
and in your pagination.blade.php file use this helper method to format numbers like:
<li class="page-item"><a class="page-link" href="{{ $url }}">{{ toBengaliNum($page) }}</a></li>
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
This is my view:
#foreach($questions as $q)
print question {{ $q->name }}
#foreach($answer as $a)
#if($a->question_id == $q->id)
print answer {{ $a->name }} //here I want only one answer
#endif
#endforeach
#endforeach
And this is my controller:
$questions = Question::get();
$answer = Answer::get();
return view('page', compact('questions', 'answer'));
I want to print questions, then only one answer per question. As there are many answers per question how can I limit it to print only one? Do I do it in controller somehow? I'm sorry I'm asking this a bit stupit question but I didn't know how to google it.
Assuming you've got relationships properly set up, it's as easy as this using Laravel's Collection class first method:
#foreach($questions as $q)
print question {{ $q->name }}
print answer {{ $q->answers->first()->name }}
#endforeach
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
str = "This website is <a href='www.google.com'>Google</a>, some other website is <a href='www.facebook.com'>Facebook</a>"
style_to_add = "style='text-decoration:none;'"
I want to add the style_to_add string to every hyperlink. So the result becomes
str = "This website is <a href='www.google.com' style='text-decoration:none;>Google</a>, some other website is <a href='www.facebook.com' style='text-decoration:none;>Facebook</a>"
This regex will work
(href='[^']+')
Regex Demo
More accurate regex will be to use
(\bhref='[>']+)>
Ruby Code
pattern = %r{(href='[^']+')}
str = "This website is <a href='www.google.com'>Google</a>, some other website is <a href='www.facebook.com'>Facebook</a>"
style_to_add = "style='text-decoration:none;'"
print str.gsub(pattern, '\1 ' + style_to_add)
Ideone Demo
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I know this error happens when I forget to wrap a sequence in parenthesis. But I was playing with this query for a while and put parenthesis where I saw fit. I still cannot get this query to work
<ul>
{for $R in doc("exp.xml")/exp/R
let $groups := tokenize($R/#an_attribute, '\s')
return (
<li>
<div>{$R}</div>
<ol>
for $group in $groups
return (<li>{$group}</li>)
</ol>
</li>
)
}
</ul>
you're missing the brackets to run the FLOWR inside the tag!
<ol>
{
for $group in $groups
return <li>{ $group }</li>
}
</ol>
and that's why you're getting the "variable has not been declared": it's not setting the for loop variable $group at all
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am trying to extract the content of a string that is formatted in the following manner:
<script type="text/javascript">
document.viewData = THE INFORMATION I WANT
</script> some other stuff
Any ideas on how to implement that?
Thanks in advance!
Your text data:
text = <<-_TEXT_
<script type="text/javascript">
document.viewData = THE INFORMATION I WANT
</script> some other stuff
_TEXT_
Setup a regular expression
re = /document\.viewData = (.*)/
apply it to the text and get the result
result = (text.match re)[1]
print result
require 'nokogiri'
doc = Nokogiri::XML::Document.parse <<-_XML_
<script type="text/javascript">
document.viewData = THE INFORMATION I WANT
</script> some other stuff
_XML_
doc.at('//script').text.strip.split("=").last
# => " THE INFORMATION I WANT"
Depending on how strict you can be, this can do the work (the result in the match group):
<script type="text\/javascript">\W+document.viewData =\s+([^<]+)\W+\s+<\/script>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
using nokogiri,
i want to find <p class="main"> Some text here...</p>
from an html document,
and then output the location as below or something that shows the tree
html > body > div class = "body" > p class= "main "
text="<html><body><div class='body'><p class='main'>some text here</p></div></body></html>"
doc = Nokogiri::HTML(text)
root = doc.root
node = doc.xpath('//p[#class="main"]').first
path = [node]
begin
node = node.parent
path.unshift node
end until node == root
path.map {|n| n.name}.join " > "
Exercise for you to add whichever attributes you want.