使用Axios切换Laravel语言环境

时间:2018-09-13 16:48:44

标签: laravel session localization locale axios

我想通过axios呼叫更改语言环境:

import cv2
import numpy as np

image=cv2.imread("/home/pi/Downloads/test.jpg")
face_cascade=cv2.CascadeClassifier("/home/pi/opencv-3.4.0/data/haarcascades/haarcascade_frontalface_alt.xml")
profil_cascade=cv2.CascadeClassifier("/home/pi/opencv-3.4.0/data/haarcascades/haarcascade_profileface_alt.xml")

gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
face=face_cascade.detectMultiScale(gray, 1.06, 5)
profil=profil_cascade.detectMultiScale(gray, 1.1, 5)

combined_array=np.append(face, profil, axis=0)
combined_list=combined_array.tolist()
result=cv2.groupRectangles(combined_list,2)

print("I've found "+str(len(result))+ " face(s)")

for (x,y,w,h) in result[0]:
    cv2.rectangle(image,(x,y),(x+w,y+h),(0,0,255),2)

cv2.imwrite("/home/pi/Download/result.jpg", image)

我的API路线:

Option Explicit

Sub ImportData()
Dim fPath As String
Dim fName As String
Dim thisFile As String
Dim thisTab As String
Dim fSheets As Variant
Dim fSheet As Variant
'
'
fPath = "C:\CliffTemp\ProjectionsFile_TY.xlsx"
fName = "Projections_TY.xlsx"
thisFile = "Projections_ReportingTEMP.xlsm"
thisTab = "Projections"
'

fSheets = Array("10000", "20100", "30101", "40200", "50300")

    'Update Projections_ReportingTEMP file

    'Open Projections_TY file: Projections_TY.xlsx
    Application.EnableCancelKey = xlDisabled 'fixes the "Code error msg..
    Workbooks.Open Filename:=fPath, UpdateLinks:=False
    Windows(fName).Activate

    For Each fSheet In fSheets
    Sheets(fSheet).Select


    Range("G3").Select
    ActiveCell.FormulaR1C1 = "=RIGHT(TRIM(CELL(""filename"")),6)"
    Range("G3:T120").Select
    Selection.Copy
    Windows(thisFile).Activate
    Sheets(thisTab).Select
    Range("F2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    'Activate Projections_TY.xlsx
    Windows(fName).Activate

    Next fSheet

我的会话中间件:

changeLanguage(code) {
                return axios
                    .put(`/api/lang/` + code)
                    .then(response => {
                        console.log(response.data);
                    })
                    .catch(err => {
                        return "Error switching language";
                        console.log(err.response);
                    });
            },

我的LanguageController:

Route::group(['middleware' => ['sessions']], function () {
    Route::put('lang/{language}', 'LanguageController@switchLang');
});

我的IndexController:

'sessions' => [
            \Illuminate\Session\Middleware\StartSession::class,
        ]

问题在于LanguageController无法设置可以从IndexController读取的会话变量。它表明它们不共享相同的会话变量。每次刷新页面时,它都会显示旧语言。

使用Axios更改当前语言环境的正确方法是什么?

0 个答案:

没有答案