I'm implementing translation on my Symfony3 app. I read the book and implemented the _locale var at the beginning of my route. I've also set a redirection from / to /en, and define the translator fallbacks.
This is working as intend, except for FOSUserBundle route. Since they aren't define on my own routing, they don't take care of the {_locale}, and they reset to the default language when I visit them. (/de/mypage => /profile => /en/mypage)
My translation files are stored in app/ressources/translations, and all my translation are done twig side.
app_localized:
resource: "#AppBundle/Controller/"
type: annotation
prefix: /{_locale}
app:
path: /
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /en
permanent: true
I saw in the book it was advised to set the translation in controller, but in my case, I got some, and don't think it's valuable to repeat in each of them the language check.
I have also thinking of store the _locale var in session, and put a globale listener, but seems a bit too much, so i think i am probably missing something.
So, how to handle globale language throught URL, including on FOSUserBundle route, without repeat code in each controller?
Actually, my FOSRout are like that.
fos_js_routing:
resource: "#FOSJsRoutingBundle/Resources/config/routing/routing.xml"
fos_user_security:
resource: "#FOSUserBundle/Resources/config/routing/security.xml"
prefix: /{_locale}
requirements:
_locale: '%app_locales%'
fos_user_profile:
resource: "#FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /{_locale}/profile
requirements:
_locale: '%app_locales%'
fos_user_register:
resource: "#FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /{_locale}/register
requirements:
_locale: '%app_locales%'
fos_user_resetting:
resource: "#FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /{_locale}/resetting
requirements:
_locale: '%app_locales%'
fos_user_change_password:
resource: "#FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /{_locale}/profile
requirements:
_locale: '%app_locales%'
Did you set these parameters in the framework section of the config.yml file :
framework:
translator: { fallbacks: ["%locale%"] }
default_locale: "%locale%"
And you need to prefix the FOSUserBundle routes too in the routing.yml file like this :
fos_user_security:
resource: "#FOSUserBundle/Resources/config/routing/security.xml"
prefix: /{_locale}/
requirements:
_locale: en|fr
fos_user_profile:
resource: "#FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /{_locale}/profile
fos_user_register:
resource: "#FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /{_locale}/register
fos_user_resetting:
resource: "#FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /{_locale}/resetting
fos_user_change_password:
resource: "#FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /{_locale}/profile
Related
When I click on the tags on the right of my Github pages, it always give me a 404 page. However, when I preview it locally, the redirect seem to work just fine:
I wonder if it has something to do with my _config.yml. I have tried different url and baseurl strings, but still couldn't resolve it.
(Note: This theme was adopted from Chirpy)
Thanks!
Part of my config.yml:
title: Changyu Yan
url: 'https://changyuyan.github.io'
# Only if your site type is GitHub Project sites and doesn't have a custom domain,
# change below value to '/projectname'.
baseurl: ''
timezone: America/Los_Angeles
google_analytics:
id: ''
pv:
# The Google Analytics pageviews switch.
# DO NOT enable it unless you know how to deploy the Google Analytics superProxy.
enabled: false
# the next options only valid when `google_analytics.pv` is enabled.
proxy_url: ''
proxy_endpoint: ''
cache: false # pv data local cache, good for the users from GFW area.
# boolean type, the global switch for ToC in posts.
toc: true
paginate: 10
kramdown:
syntax_highlighter: rouge
syntax_highlighter_opts: # Rouge Options › https://github.com/jneen/rouge#full-options
css_class: highlight
# default_lang: console
span:
line_numbers: false
block:
line_numbers: true
start_line: 1
# DO NOT change this unless you're a Pro user on Jekyll and Web development,
# or you think you're smart enough to change other relevant URLs within this template.
permalink: /posts/:title/
collections:
tabs:
output: true
sort_by: order
defaults:
-
scope:
path: '' # An empty string here means all files in the project
type: posts
values:
layout: post
comments: true # Enable comments in posts.
toc: true # Display TOC column in posts.
breadcrumb:
-
label: Posts
url: /
-
scope:
path: _drafts
values:
comments: false
-
scope:
path: index.html
values:
breadcrumb:
-
label: Posts
-
scope:
path: tags
values:
breadcrumb:
-
label: Home
url: /
-
label: Tags
url: /tabs/tags/
-
scope:
path: categories
values:
breadcrumb:
-
label: Home
url: /
-
label: Categories
url: /tabs/categories/
-
scope:
path: ''
type: tabs # see `site.collections`
values:
layout: page
dynamic_title: true # Hide title in mobile screens.
breadcrumb:
-
label: Home
url: /
sass:
sass_dir: /assets/css
style: compressed
compress_html:
clippings: all
comments: all
endings: all
profile: false
blanklines: false
ignore:
envs: []
exclude:
- vendor
- Gemfile.lock
- Gemfile
- tools
- docs
- README.md
- LICENSE
jekyll-archives:
enabled: [categories, tags]
layouts:
category: category
tag: tag
permalinks:
tag: /tags/:name/
category: /categories/:name/
The archives are working locally and not on GitHub Pages because the jekyll-archives gem is not supported in GitHub Pages. You can see in the notes for Chirpy, under Deploy on GitHub Pages, an option for using GitHub Actions. This should allow you to run unsupported plugins (there is a good tutorial by Aneejian).
Another option is to manually build all your tag pages. You would need to create a tag directory and inside that, create all the tag files (software-engineering.html). Inside those you'd run a for loop for that tag. You have a couple of options:
{% for post in site.tags.software-engineering %}
or
{% for post in site.posts | where: 'tag', 'software-engineering' %}
There are others that may better suit your use-case.
Per the baseurl discussion, you do not need that if you do not use a project directory. If you wanted https://changyuyan.github.io/blog/tags/software-engineering/, you'd need to add baseurl: '/blog ...but it doesn't look like you want that.
Near the top of your _config.yml, set baseurl to the name of the project repo according to the instructions:
# Only if your site type is GitHub Project sites and doesn't have a custom domain,
# change below value to '/projectname'.
baseurl: '/changyuyan.github.io'
I am trying to use nestjs/swagger to create a swagger file from my back-end and I am facing a problem related to the base path. What I want to achieve is to show version as base path instead of showing it in all the methods available, which is ugly and confusing.
My API, right now, has the following structure (this is a set of what is present in app.module.ts):
const routes: Routes = [
{
path: '/api',
module: ApiModule,
children: [
{
path: '/v1',
module: V1Module,
children: [
{
path: '/orders',
module: OrdersModule
},
{
path: '/users',
module: UsersModule
}
]
}
]
}
];
This way, once I generate and check the swagger, I see all my methods following the /api/v1 prefix. This could be an example:
orders
GET /api/v1/orders
POST /api/v1/orders
GET /api/v1/orders/{order_id}
...
users
GET /api/v1/users
POST /api/v1/users
GET /api/v1/users/{user_id}
...
What I want is to get rid of /api/v1 appearing in any method. I know that SWAGGER has fields for host and basePath, but do not find any way to populate it in Nest.js. Researching, I have found that there were .setBasePath() and .addServer() methods, but they do not work for me (I am pretty sure they are deprecated).
Thank very much for your help.
If you want nestjs to add api/v1 to every endpoint then use setGlobalPrefix('api/v1') to do that.
https://docs.nestjs.com/faq/global-prefix#global-prefix
I'm trying to use some open source ruby software, with limited familarity with ruby. The original code supported two URLs, mainSite and api.mainsite
I want to change this so these two locations point to the same localhost, and am having difficulty. Here is a snippet of the code that I think is relelvant.
lambda_api_host = lambda { |request| request.host == URI.parse(Api::Application.config.api_url).host }
lambda_www_host = lambda { |request| request.host == URI.parse(Api::Application.config.www_url)
#www.mainSite.com
scope constraints: lambda_www_host do
...
end
# api.mainSite.com
scope constraints: lambda_api_host do
....
end
I've read through the routes.rb and tried a few changes but so far none have worked. I can't get the "api" one to point to localhost without an internal error.
Note, the code has redirects that use Api::Application.config.api_url to build the url to redirect to
I have created a site using LocomotiveCMS, I have created two content types called Photo and Gallery, these content types have a relationship so that I can create image galleries on my site.
I am currently looking to use the RESTful API in order to create multiple content entries for Photo as it traverses through a file.
I can connect to the API with no issue and modify the site etc.
I would assume that the cURL command for a new content entry would take the form of:
curl -X POST -d 'photo[image_id]=blah&photo[gallery]=1234&photo[file]=<filepath>photo[published]=true' 'http://<your site>/locomotive/api/current_site.json?auth_token=xxxx'
However I am unsure how to pass a file through in this command, I have substituted this for for now, how would you write this part?
My fields are set up as follows for Photo:
fields:
- image_id:
label: Image ID
type: string
required: true
localized: false
- file: # Name of the field
label: File
type: file
required: true
localized: false
- gallery: # Name of the field
label: Gallery
type: belongs_to
required: true
localized: false
# Slug of the target content type (eg post if this content type is a comment)
class_name: gallery
I ended up making a Ruby Script to parse files and upload them by sending the post data to
/locomotive/api/content_types/photos/entries.json?auth_token=XXXX
The following code can potentially help with this task:
data = {
content_entry: {
title: 'Title',
image: File.new('media/images/screen.png'),
}
}
HTTMultiParty.post(
"http://localhost:8080/locomotive/content_types/blogs/entries.json?auth_token=#{#token}",
query: data,
headers: { 'Content-Type' => 'application/json' }
)
I'm using HTTMultiParty since we actually need to do a multipart-post. Helpful information on how to do this with curl:
https://github.com/locomotivecms/documentation/pull/175
To get the token you need something like this:
HTTParty.post(
'http://localhost:8080/locomotive/api/tokens.json',
body: { api_key: 'YOUR_API_KEY_HERE' }
)
I hope that helps.
There is an api gem for LocomotiveCMS by now, works for 2.5.x and 3.x https://github.com/locomotivecms/coal
the attribute used need to end with _url for content entry fields with type=file https://github.com/locomotivecms/engine/pull/511/commits/f3a47ba5672b7a560e5edbef93cc9a4421192f0a
This follows on from my other question I posted.
I need to make it so that when anyone logs in they are redirected to a particular module - sfGuardUser and action isExistingUser. I know it is somehting to do with the routing, but I am absolutely clueless with this file, I can't make head nor tail of it, and none of the tutorials online are making any sense to me.
The problem is complicated (I think) further by the fact that if someone logs out (clicking a link logout) their url in the browser doesn't change, so therefore if they log on from that same screen, symfony tries to take them to whatever url they already have in their browser. I'm not sure how to account for this in my routing.
I have two apps - frontend and backend. I think users log in from the frontend (I'm not sure to be honest), but I think it's the frontend because when they login, they are taken to a module int he frontend app. Although looking at the settings.yml for both apps, the login module is enabled for both :S
Here is my routing file for the front end:
homepage:
url: /
param: { module: investigation, action: isExistingUser }
default_index:
url: /:module
param: { module: investigation, action: isExistingUser }
default:
url: /:module/:action/*
param: { module: investigation, action: isExistingUser }
And the backend:
homepage:
url: /
param: { module: sfGuardUser, action: index }
sfGuardUser:
url: /sf_guard_user
param: { module: sfGuardUser, action: index }
default_index:
url: /:module
param: { action: index }
default:
url: /:module/:action/*
you set the route used after sign_in or sign_out in the app.yml for each project.
For example in apps/(backend|frontend)/config/app.yml:
all:
sf_guard_plugin:
success_signin_url: #my_route?param=value # the plugin use the referer as default
success_signout_url: module/action # the plugin use the referer as default
found in the extra documentation of sfguardplugin ;)